Commit fabf7361 by Qiang Huang Committed by Serge Hallyn

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: 's avatarQiang Huang <h.huangqiang@huawei.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent 38973621
......@@ -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++)
......
......@@ -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
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment