]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Logging: don't confuse command line and config file specified values
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 6 Aug 2013 19:56:48 +0000 (14:56 -0500)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Wed, 7 Aug 2013 13:55:37 +0000 (08:55 -0500)
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 <serge.hallyn@ubuntu.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c

index 46320dd00599261e942245c1508c7c903d93d6a3..53c05e6670bd452578c10eda111d6f7e6b40aca6 100644 (file)
@@ -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;
index ed3240daa1b081ab4904eda55facdd994bd27e41..d6f85c8fa1a0b655e284b6f444323662c5653f18 100644 (file)
@@ -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,
index bb02e1c75618b7aeb8f64ee057dc35984aafd54f..f44835bb79b957ffb4820b367b24a342f6095857 100644 (file)
@@ -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);