]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-execute: allow lxc-init to log only when we have a valid log level
authorQiang Huang <h.huangqiang@huawei.com>
Fri, 7 Jun 2013 07:27:32 +0000 (15:27 +0800)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 10 Jun 2013 12:20:38 +0000 (07:20 -0500)
Right now if we use lxc-execute without log level set, we get error:
lxc: invalid log priority NOTSET.
Because we set log level manually in execute_start(), but didn't
check if we have a valid log level or not, so fix it.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/execute.c
src/lxc/log.c
src/lxc/log.h

index 9bf33cae661bbcdcde32e9c3e0a75dace4fb8ef3..ec5cd29d9fd36e3e916a9dbb14affe599a7242cc 100644 (file)
@@ -96,8 +96,11 @@ static int execute_start(struct lxc_handler *handler, void* data)
        argc_add = 4;
        if (my_args->quiet)
                argc_add++;
-       if (!handler->conf->rootfs.path)
-               argc_add+=6;
+       if (!handler->conf->rootfs.path) {
+               argc_add += 4;
+               if (lxc_log_has_valid_level())
+                       argc_add += 2;
+       }
 
        argv = malloc((argc + argc_add) * sizeof(*argv));
        if (!argv)
@@ -116,8 +119,12 @@ static int execute_start(struct lxc_handler *handler, void* data)
                argv[i++] = (char *)handler->name;
                argv[i++] = "--lxcpath";
                argv[i++] = (char *)handler->lxcpath;
-               argv[i++] = "--logpriority";
-               argv[i++] = (char *)lxc_log_priority_to_string(lxc_log_get_level());
+
+               if (lxc_log_has_valid_level()) {
+                       argv[i++] = "--logpriority";
+                       argv[i++] = (char *)
+                               lxc_log_priority_to_string(lxc_log_get_level());
+               }
        }
        argv[i++] = "--";
        for (j = 0; j < argc; j++)
index d49a54458b64d628f3ee8f161bace566566e25c1..6c275ac7716a226c107421c62372ce62d214476a 100644 (file)
@@ -370,6 +370,14 @@ extern int lxc_log_get_level(void)
        return lxc_log_category_lxc.priority;
 }
 
+extern bool lxc_log_has_valid_level(void)
+{
+       int log_level = lxc_log_get_level();
+       if (log_level < 0 || log_level >= LXC_LOG_PRIORITY_NOTSET)
+               return false;
+       return true;
+}
+
 /*
  * This is called when we read a lxc.logfile entry in a lxc.conf file.  This
  * happens after processing command line arguments, which override the .conf
index 2fd40500041c8d45a19d48d275b72fb957b36fcd..03dd569f730baf5a59da316509e6d2e7dded6f6b 100644 (file)
@@ -28,6 +28,7 @@
 #include <stdio.h>
 #include <sys/time.h>
 #include <string.h>
+#include <stdbool.h>
 
 #ifndef O_CLOEXEC
 #define O_CLOEXEC 02000000
@@ -296,5 +297,6 @@ extern int lxc_log_set_level(int level);
 extern void lxc_log_set_prefix(const char *prefix);
 extern const char *lxc_log_get_file(void);
 extern int lxc_log_get_level(void);
+extern bool lxc_log_has_valid_level(void);
 extern const char *lxc_log_get_prefix(void);
 #endif