static int config_logfile(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
- char *path;
-
- // if given a blank entry, null out any previous entries.
- if (!value || strlen(value) == 0) {
- if (lxc_conf->logfile) {
- free(lxc_conf->logfile);
- lxc_conf->logfile = NULL;
- }
+ if (lxc_log_get_file()) {
+ DEBUG("Log file already specified - ignoring new value");
return 0;
}
- path = strdup(value);
- if (!path) {
- SYSERROR("failed to strdup '%s': %m", value);
- return -1;
- }
-
- if (lxc_log_set_file(path)) {
- free(path);
- return -1;
- }
-
- if (lxc_conf->logfile)
- free(lxc_conf->logfile);
- lxc_conf->logfile = path;
-
- return 0;
+ return lxc_log_set_file(value);
}
static int config_loglevel(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
+ int newlevel;
+
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')
- lxc_conf->loglevel = atoi(value);
+ newlevel = atoi(value);
else
- lxc_conf->loglevel = lxc_log_priority_to_int(value);
- return lxc_log_set_level(lxc_conf->loglevel);
+ newlevel = lxc_log_priority_to_int(value);
+ return lxc_log_set_level(newlevel);
}
static int config_autodev(const char *key, const char *value,
v = c->aa_profile;
#endif
else if (strcmp(key, "lxc.logfile") == 0)
- v = c->logfile;
+ v = lxc_log_get_file();
else if (strcmp(key, "lxc.loglevel") == 0)
- v = lxc_log_priority_to_string(c->loglevel);
+ v = lxc_log_priority_to_string(lxc_log_get_level());
else if (strcmp(key, "lxc.cgroup") == 0) // all cgroup info
return lxc_get_cgroup_entry(c, retv, inlen, "all");
else if (strncmp(key, "lxc.cgroup.", 11) == 0) // specific cgroup info
if (c->aa_profile)
fprintf(fout, "lxc.aa_profile = %s\n", c->aa_profile);
#endif
- 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);
+ 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());
lxc_list_for_each(it, &c->cgroup) {
struct lxc_cgroup *cg = it->elem;
fprintf(fout, "lxc.cgroup.%s = %s\n", cg->subsystem, cg->value);
int lxc_log_fd = -1;
static char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc";
-int lxc_loglevel_specified = 0;
+static int lxc_loglevel_specified = 0;
lxc_log_define(lxc_log, lxc);
if (prefix)
lxc_log_setprefix(prefix);
- if (file) {
- int fd;
-
- fd = log_open(file);
- if (fd == -1) {
- ERROR("failed to initialize log service");
- return -1;
- }
-
- lxc_log_fd = fd;
- }
+ if (file)
+ return lxc_log_set_file(file);
return 0;
}
return 0;
}
+char *log_fname; // default to NULL, set in lxc_log_set_file.
+
/*
* 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
* settings. So only set the logfile if previously unset.
*/
-extern int lxc_log_set_file(char *fname)
+extern int lxc_log_set_file(const char *fname)
{
if (lxc_log_fd != -1) {
- INFO("Configuration file was specified on command line, configuration file entry being ignored");
- return 0;
+ // this should've been caught at config_logfile.
+ ERROR("Race in setting logfile?");
+ return -1;
}
+
lxc_log_fd = log_open(fname);
if (lxc_log_fd == -1) {
ERROR("failed to open log file %s\n", fname);
return -1;
}
+
+ log_fname = strdup(fname);
return 0;
}
+
+extern int lxc_log_get_level(void)
+{
+ if (!lxc_loglevel_specified)
+ return LXC_LOG_PRIORITY_NOTSET;
+ return lxc_log_category_lxc.priority;
+}
+
+extern const char *lxc_log_get_file(void)
+{
+ return log_fname;
+}