mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-16 04:04:48 +00:00
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 <serge.hallyn@ubuntu.com>
This commit is contained in:
parent
96532523ef
commit
b40a606e52
@ -2123,6 +2123,7 @@ struct lxc_conf *lxc_conf_init(void)
|
|||||||
}
|
}
|
||||||
memset(new, 0, sizeof(*new));
|
memset(new, 0, sizeof(*new));
|
||||||
|
|
||||||
|
new->loglevel = LXC_LOG_PRIORITY_NOTSET;
|
||||||
new->personality = -1;
|
new->personality = -1;
|
||||||
new->console.log_path = NULL;
|
new->console.log_path = NULL;
|
||||||
new->console.log_fd = -1;
|
new->console.log_fd = -1;
|
||||||
|
@ -288,6 +288,14 @@ struct lxc_conf {
|
|||||||
int stopsignal; // signal used to stop container
|
int stopsignal; // signal used to stop container
|
||||||
int kmsg; // if 1, create /dev/kmsg symlink
|
int kmsg; // if 1, create /dev/kmsg symlink
|
||||||
char *rcfile; // Copy of the top level rcfile we read
|
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,
|
int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf,
|
||||||
|
@ -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,
|
static int config_logfile(const char *key, const char *value,
|
||||||
struct lxc_conf *lxc_conf)
|
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);
|
return lxc_log_set_file(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1009,6 +1014,9 @@ static int config_loglevel(const char *key, const char *value,
|
|||||||
newlevel = atoi(value);
|
newlevel = atoi(value);
|
||||||
else
|
else
|
||||||
newlevel = lxc_log_priority_to_int(value);
|
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);
|
return lxc_log_set_level(newlevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1873,10 +1881,10 @@ void write_config(FILE *fout, struct lxc_conf *c)
|
|||||||
if (c->aa_profile)
|
if (c->aa_profile)
|
||||||
fprintf(fout, "lxc.aa_profile = %s\n", c->aa_profile);
|
fprintf(fout, "lxc.aa_profile = %s\n", c->aa_profile);
|
||||||
#endif
|
#endif
|
||||||
if (lxc_log_get_level() != LXC_LOG_PRIORITY_NOTSET)
|
if (c->loglevel != LXC_LOG_PRIORITY_NOTSET)
|
||||||
fprintf(fout, "lxc.loglevel = %s\n", lxc_log_priority_to_string(lxc_log_get_level()));
|
fprintf(fout, "lxc.loglevel = %s\n", lxc_log_priority_to_string(c->loglevel));
|
||||||
if (lxc_log_get_file())
|
if (c->logfile)
|
||||||
fprintf(fout, "lxc.logfile = %s\n", lxc_log_get_file());
|
fprintf(fout, "lxc.logfile = %s\n", c->logfile);
|
||||||
lxc_list_for_each(it, &c->cgroup) {
|
lxc_list_for_each(it, &c->cgroup) {
|
||||||
struct lxc_cgroup *cg = it->elem;
|
struct lxc_cgroup *cg = it->elem;
|
||||||
fprintf(fout, "lxc.cgroup.%s = %s\n", cg->subsystem, cg->value);
|
fprintf(fout, "lxc.cgroup.%s = %s\n", cg->subsystem, cg->value);
|
||||||
|
Loading…
Reference in New Issue
Block a user