From: Serge Hallyn Date: Tue, 6 Aug 2013 19:56:48 +0000 (-0500) Subject: Logging: don't confuse command line and config file specified values X-Git-Tag: lxc-1.0.0.alpha1~1^2~104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b40a606e52c788db85fe1c42d3747483d159b6a5;p=thirdparty%2Flxc.git Logging: don't confuse command line and config file specified values Currently if loglevel/logfile are specified on command line in a program using LXC api, and that program does any container->save_config(), then the new config will be saved with the loglevel/logfile specified on command line. This is wrong, especially in the case of cat > lxc.conf << EOF lxc.logfile=a EOF lxc-create -t cirros -n c1 -o b which will result in a container config with lxc.logfile=b. Signed-off-by: Serge Hallyn --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 46320dd00..53c05e667 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -2123,6 +2123,7 @@ struct lxc_conf *lxc_conf_init(void) } memset(new, 0, sizeof(*new)); + new->loglevel = LXC_LOG_PRIORITY_NOTSET; new->personality = -1; new->console.log_path = NULL; new->console.log_fd = -1; diff --git a/src/lxc/conf.h b/src/lxc/conf.h index ed3240daa..d6f85c8fa 100644 --- a/src/lxc/conf.h +++ b/src/lxc/conf.h @@ -288,6 +288,14 @@ struct lxc_conf { int stopsignal; // signal used to stop container int kmsg; // if 1, create /dev/kmsg symlink char *rcfile; // Copy of the top level rcfile we read + + // Logfile and logleve can be set in a container config file. + // Those function as defaults. The defaults can be overriden + // by command line. However we don't want the command line + // specified values to be saved on c->save_config(). So we + // store the config file specified values here. + char *logfile; // the logfile as specifed in config + int loglevel; // loglevel as specifed in config (if any) }; int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf, diff --git a/src/lxc/confile.c b/src/lxc/confile.c index bb02e1c75..f44835bb7 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -990,6 +990,11 @@ static int config_aa_profile(const char *key, const char *value, static int config_logfile(const char *key, const char *value, struct lxc_conf *lxc_conf) { + // store these values in the lxc_conf, and then try to set for + // actual current logging. + if (lxc_conf->logfile) + free(lxc_conf->logfile); + lxc_conf->logfile = strdup(value); return lxc_log_set_file(value); } @@ -1009,6 +1014,9 @@ static int config_loglevel(const char *key, const char *value, newlevel = atoi(value); else newlevel = lxc_log_priority_to_int(value); + // store these values in the lxc_conf, and then try to set for + // actual current logging. + lxc_conf->loglevel = newlevel; return lxc_log_set_level(newlevel); } @@ -1873,10 +1881,10 @@ void write_config(FILE *fout, struct lxc_conf *c) if (c->aa_profile) fprintf(fout, "lxc.aa_profile = %s\n", c->aa_profile); #endif - if (lxc_log_get_level() != LXC_LOG_PRIORITY_NOTSET) - fprintf(fout, "lxc.loglevel = %s\n", lxc_log_priority_to_string(lxc_log_get_level())); - if (lxc_log_get_file()) - fprintf(fout, "lxc.logfile = %s\n", lxc_log_get_file()); + if (c->loglevel != LXC_LOG_PRIORITY_NOTSET) + fprintf(fout, "lxc.loglevel = %s\n", lxc_log_priority_to_string(c->loglevel)); + if (c->logfile) + fprintf(fout, "lxc.logfile = %s\n", c->logfile); lxc_list_for_each(it, &c->cgroup) { struct lxc_cgroup *cg = it->elem; fprintf(fout, "lxc.cgroup.%s = %s\n", cg->subsystem, cg->value);