Bläddra i källkod

HPCC-23914 Fix eclcc --help and handle various illegal options better

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 5 år sedan
förälder
incheckning
3d4402eb9e
2 ändrade filer med 47 tillägg och 17 borttagningar
  1. 20 7
      ecl/eclcc/eclcc.cpp
  2. 27 10
      system/jlib/jptree.cpp

+ 20 - 7
ecl/eclcc/eclcc.cpp

@@ -516,17 +516,30 @@ int main(int argc, const char *argv[])
     InitModuleObjects();
     queryStderrLogMsgHandler()->setMessageFields(0);
 
-    configuration.setown(loadConfiguration(defaultYaml, argv, "eclccserver", "ECLCCSERVER", nullptr, nullptr));
+    unsigned exitCode = 0;
+    try
+    {
+        configuration.setown(loadConfiguration(defaultYaml, argv, "eclccserver", "ECLCCSERVER", nullptr, nullptr));
 
 #ifndef _CONTAINERIZED
-    // Turn logging down (we turn it back up if -v option seen)
-    Owned<ILogMsgFilter> filter = getCategoryLogMsgFilter(MSGAUD_user| MSGAUD_operator, MSGCLS_error);
-    queryLogMsgManager()->changeMonitorFilter(queryStderrLogMsgHandler(), filter);
+        // Turn logging down (we turn it back up if -v option seen)
+        Owned<ILogMsgFilter> filter = getCategoryLogMsgFilter(MSGAUD_user| MSGAUD_operator, MSGCLS_error);
+        queryLogMsgManager()->changeMonitorFilter(queryStderrLogMsgHandler(), filter);
 #else
-    setupContainerizedLogMsgHandler();
+        setupContainerizedLogMsgHandler();
 #endif
-    unsigned exitCode = doMain(argc, argv);
-    stopPerformanceMonitor();
+        exitCode = doMain(argc, argv);
+        stopPerformanceMonitor();
+    }
+    catch (IException *E)
+    {
+        StringBuffer m("Error: ");
+        E->errorMessage(m);
+        fputs(m.newline().str(), stderr);
+        E->Release();
+        exitCode = 2;
+    }
+
     if (!optReleaseAllMemory)
     {
         //In release mode exit without calling all the clean up code.

+ 27 - 10
system/jlib/jptree.cpp

@@ -7767,7 +7767,7 @@ static IPropertyTree * loadConfiguration(const char * filename, const char * com
 
     const char * ext = pathExtension(filename);
     Owned<IPropertyTree> configTree;
-    if (strieq(ext, ".yaml"))
+    if (!ext || strieq(ext, ".yaml"))
     {
         try
         {
@@ -7784,7 +7784,9 @@ static IPropertyTree * loadConfiguration(const char * filename, const char * com
     else
         throw makeStringExceptionV(99, "Unrecognised file extension %s", ext);
 
-    assert(configTree);
+    if (!configTree)
+        throw makeStringExceptionV(99, "Error loading configuration file %s", filename);
+
     IPropertyTree * config = configTree->queryPropTree(componentTag);
     if (!config)
     {
@@ -7866,6 +7868,10 @@ static const char * extractOption(const char * option, const char * cur)
 
 static void applyCommandLineOption(IPropertyTree * config, const char * option, const char * value)
 {
+    //Ignore -- with no following option.
+    if (isEmptyString(option))
+        return;
+
     const char *tail;
     while ((tail = strchr(option, '.')) != nullptr)
     {
@@ -7880,6 +7886,10 @@ static void applyCommandLineOption(IPropertyTree * config, const char * option,
         }
         option = tail+1;
     }
+
+    if (!validateXMLTag(option))
+        throw makeStringExceptionV(99, "Invalid option name '%s'", option);
+
     StringBuffer path;
     path.append('@').append(option);
     config->setProp(path, value);
@@ -7983,9 +7993,12 @@ jlib_decl IPropertyTree * loadConfiguration(const char * defaultYaml, const char
             optConfig = matchConfig;
         else if (strsame(cur, "--help"))
         {
+#if 0
+            //Better not to include this until it has been implemented, since it breaks eclcc
             //MORE: displayHelp(config);
-            printf("%s <options>", argv[0]);
+            printf("%s <options>\n", argv[0]);
             exit(0);
+#endif
         }
         else if (strsame(cur, "--init"))
         {
@@ -8018,15 +8031,19 @@ jlib_decl IPropertyTree * loadConfiguration(const char * defaultYaml, const char
         if (streq(optConfig, "1"))
             throw makeStringExceptionV(99, "Name of configuration file omitted (use --config=<filename>)");
 
-        StringBuffer fullpath;
-        if (!isAbsolutePath(optConfig))
+        //--config= with no filename can be used to ignore the legacy configuration file
+        if (!isEmptyString(optConfig))
         {
-            appendCurrentDirectory(fullpath, false);
-            addNonEmptyPathSepChar(fullpath);
+            StringBuffer fullpath;
+            if (!isAbsolutePath(optConfig))
+            {
+                appendCurrentDirectory(fullpath, false);
+                addNonEmptyPathSepChar(fullpath);
+            }
+            fullpath.append(optConfig);
+            delta.setown(loadConfiguration(fullpath, componentTag, true, altNameAttribute));
+            globalConfiguration.setown(loadConfiguration(fullpath, "global", false, altNameAttribute));
         }
-        fullpath.append(optConfig);
-        delta.setown(loadConfiguration(fullpath, componentTag, true, altNameAttribute));
-        globalConfiguration.setown(loadConfiguration(fullpath, "global", false, altNameAttribute));
     }
     else
     {