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>
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)
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++)
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
#include <stdio.h>
#include <sys/time.h>
#include <string.h>
+#include <stdbool.h>
#ifndef O_CLOEXEC
#define O_CLOEXEC 02000000
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