In current LXC, loglevel and logfile are write-once functions.
That behaviour was appropriate when those two were first introduced
(pre-API) but with current API, one would expect to be able to
set_config_item those multiple times.
So instead, introduce lxc_log_options_no_override which when called
turns those two config keys read-only and have all existing binaries
which use log_init call that function once they're done setting the
value requested by the user.
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
if (!value || strlen(value) == 0)
return 0;
- if (lxc_log_get_level() != LXC_LOG_PRIORITY_NOTSET) {
- DEBUG("Log level already set - ignoring new value");
- return 0;
- }
if (value[0] >= '0' && value[0] <= '9')
newlevel = atoi(value);
else
free(log_fname);
}
+ if (!fname || strlen(fname) == 0) {
+ log_fname = NULL;
+ return 0;
+ }
+
#if USE_CONFIGPATH_LOGS
// we don't build_dir for the default if the default is
// i.e. /var/lib/lxc/$container/$container.log
return -1;
}
- lxc_loglevel_specified = 1;
lxc_priority = lxc_log_priority_to_int(priority);
}
if (file) {
if (strcmp(file, "none") == 0)
return 0;
- lxc_logfile_specified = 1;
ret = __lxc_log_set_file(file, 1);
} else {
ERROR("invalid log priority %d", level);
return -1;
}
- lxc_loglevel_specified = 1;
lxc_log_category_lxc.priority = level;
return 0;
}
extern int lxc_log_get_level(void)
{
- if (!lxc_loglevel_specified)
- return LXC_LOG_PRIORITY_NOTSET;
return lxc_log_category_lxc.priority;
}
{
if (lxc_logfile_specified)
return 0;
- lxc_logfile_specified = 1;
return __lxc_log_set_file(fname, 0);
}
{
return log_prefix;
}
+
+extern void lxc_log_options_no_override()
+{
+ if (lxc_log_get_file())
+ lxc_logfile_specified = 1;
+
+ if (lxc_log_get_level() != LXC_LOG_PRIORITY_NOTSET)
+ lxc_loglevel_specified = 1;
+}
extern int lxc_log_get_level(void);
extern bool lxc_log_has_valid_level(void);
extern const char *lxc_log_get_prefix(void);
+extern void lxc_log_options_no_override();
#endif
my_args.progname, my_args.quiet, my_args.lxcpath[0]);
if (ret)
return ret;
+ lxc_log_options_no_override();
if (remount_sys_proc)
attach_options.attach_flags |= LXC_ATTACH_REMOUNT_PROC_SYS;
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
return -1;
+ lxc_log_options_no_override();
state_object = my_args.argv[0];
my_args.progname, my_args.quiet, my_args.lxcpath[0]);
if (ret)
return EXIT_FAILURE;
+ lxc_log_options_no_override();
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
exit(1);
+ lxc_log_options_no_override();
memset(&spec, 0, sizeof(spec));
if (!my_args.bdevtype)
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
exit(1);
+ lxc_log_options_no_override();
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
return -1;
+ lxc_log_options_no_override();
/* rcfile is specified in the cli option */
if (my_args.rcfile)
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
exit(1);
+ lxc_log_options_no_override();
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
return ret;
+ lxc_log_options_no_override();
if (print_info(my_args.name, my_args.lxcpath[0]) == 0)
ret = EXIT_SUCCESS;
basename(argv[0]), quiet, lxcpath);
if (err < 0)
exit(EXIT_FAILURE);
+ lxc_log_options_no_override();
if (!argv[optind]) {
ERROR("missing command to launch");
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
return -1;
+ lxc_log_options_no_override();
if (quit_monitord) {
int ret = EXIT_SUCCESS;
ret = lxc_log_init(NULL, logpath, "NOTICE", "lxc-monitord", 0, lxcpath);
if (ret)
INFO("Failed to open log file %s, log will be lost", lxcpath);
+ lxc_log_options_no_override();
pipefd = atoi(argv[2]);
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
exit(1);
+ lxc_log_options_no_override();
if (geteuid()) {
if (access(my_args.lxcpath[0], O_RDWR) < 0) {
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
return err;
+ lxc_log_options_no_override();
const char *lxcpath = my_args.lxcpath[0];
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
return 1;
+ lxc_log_options_no_override();
/* Set default timeout */
if (my_args.timeout == -2) {
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
exit(1);
+ lxc_log_options_no_override();
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c) {
if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority,
my_args.progname, my_args.quiet, my_args.lxcpath[0]))
return -1;
+ lxc_log_options_no_override();
c = lxc_container_new(my_args.name, my_args.lxcpath[0]);
if (!c)
set_key(key, value)
new_value = self.get_config_item(key)
+ # loglevel is special and won't match the string we set
+ if key == "lxc.loglevel":
+ new_value = value
+
if (isinstance(value, str) and isinstance(new_value, str) and
value == new_value):
return True