From: Qiang Huang Date: Fri, 7 Jun 2013 07:27:32 +0000 (+0800) Subject: lxc-execute: allow lxc-init to log only when we have a valid log level X-Git-Tag: lxc-1.0.0.alpha1~1^2~159 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fabf7361da4845cd6cf268e0e85c3c6a1c0b0be4;p=thirdparty%2Flxc.git lxc-execute: allow lxc-init to log only when we have a valid log level 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 Signed-off-by: Serge Hallyn --- diff --git a/src/lxc/execute.c b/src/lxc/execute.c index 9bf33cae6..ec5cd29d9 100644 --- a/src/lxc/execute.c +++ b/src/lxc/execute.c @@ -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++) diff --git a/src/lxc/log.c b/src/lxc/log.c index d49a54458..6c275ac77 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -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 diff --git a/src/lxc/log.h b/src/lxc/log.h index 2fd405000..03dd569f7 100644 --- a/src/lxc/log.h +++ b/src/lxc/log.h @@ -28,6 +28,7 @@ #include #include #include +#include #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