From: Stéphane Graber Date: Wed, 23 Jan 2013 22:20:11 +0000 (-0500) Subject: Revert "use a default per-container logfile" X-Git-Tag: lxc-0.9.0.alpha3~1^2~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e6cde7418c4e697876f0041b888766ab4732812b;p=thirdparty%2Flxc.git Revert "use a default per-container logfile" The logfile changes broke lxc-info and possibly more command line tools. Revert for now until we get those issues addressed. This reverts commit 74476cf144523530022d76cef3a558b0662b592f. --- diff --git a/configure.ac b/configure.ac index 6888701c9..d1f5ad950 100644 --- a/configure.ac +++ b/configure.ac @@ -157,13 +157,6 @@ AC_ARG_WITH([rootfs-path], [lxc rootfs mount point] )], [], [with_rootfs_path=['${libdir}/lxc/rootfs']]) -# Container log path. By default, use $lxcpath. -AC_ARG_WITH([log-path], - [AC_HELP_STRING( - [--with-log-path=dir], - [per container log path] - )], [], [with_log_path=['${with_config_path}']]) - # Expand some useful variables AS_AC_EXPAND(PREFIX, "$prefix") AS_AC_EXPAND(LIBDIR, "$libdir") @@ -180,7 +173,6 @@ AS_AC_EXPAND(LXCPATH, "$with_config_path") AS_AC_EXPAND(LXCROOTFSMOUNT, "$with_rootfs_path") AS_AC_EXPAND(LXCTEMPLATEDIR, "$datadir/lxc/templates") AS_AC_EXPAND(LXCINITDIR, "$libexecdir") -AS_AC_EXPAND(LOGPATH, "$with_log_path") # Check for some standard kernel headers AC_CHECK_HEADERS([linux/unistd.h linux/netlink.h linux/genetlink.h], diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index 8b409268d..5a28af4c9 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -89,8 +89,7 @@ AM_CFLAGS=-I$(top_srcdir)/src \ -DLXCROOTFSMOUNT=\"$(LXCROOTFSMOUNT)\" \ -DLXCPATH=\"$(LXCPATH)\" \ -DLXCINITDIR=\"$(LXCINITDIR)\" \ - -DLXCTEMPLATEDIR=\"$(LXCTEMPLATEDIR)\" \ - -DLOGPATH=\"$(LOGPATH)\" + -DLXCTEMPLATEDIR=\"$(LXCTEMPLATEDIR)\" if ENABLE_APPARMOR AM_CFLAGS += -DHAVE_APPARMOR diff --git a/src/lxc/confile.c b/src/lxc/confile.c index d350f01df..67a989ed4 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -927,6 +927,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) { + if (lxc_log_get_file()) { + DEBUG("Log file already specified - ignoring new value"); + return 0; + } + return lxc_log_set_file(value); } diff --git a/src/lxc/log.c b/src/lxc/log.c index db5c52f36..d2a90de7a 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -42,8 +42,6 @@ int lxc_log_fd = -1; static char log_prefix[LXC_LOG_PREFIX_SIZE] = "lxc"; static int lxc_loglevel_specified = 0; -// if logfile was specifed on command line, it won't be overridden by lxc.logfile -static int lxc_log_specified = 0; lxc_log_define(lxc_log, lxc); @@ -150,42 +148,11 @@ static int log_open(const char *name) return newfd; } -static char *build_log_path(const char *name) -{ - char *p; - int len, ret; - - /* '$logpath' + '/' + '$name' + '/' + '$name' + '.log' + '\0' */ - len = sizeof(LOGPATH) + 2*sizeof(name) + 7; - p = malloc(len); - if (!p) - return p; - ret = snprintf(p, len, "%s/%s", LOGPATH, name); - if (ret < 0 || ret >= len) { - free(p); - return NULL; - } - ret = mkdir(p, 0755); - if (ret == -1 && errno != EEXIST) { - free(p); - return NULL; - } - ret = snprintf(p, len, "%s/%s/%s.log", LOGPATH, name, name); - if (ret < 0 || ret >= len) { - free(p); - return NULL; - } - return p; -} - /*---------------------------------------------------------------------------*/ -extern int lxc_log_init(const char *name, const char *file, - const char *priority, const char *prefix, int quiet) +extern int lxc_log_init(const char *file, const char *priority, + const char *prefix, int quiet) { int lxc_priority = LXC_LOG_PRIORITY_ERROR; - int ret; - char *tmpfile = NULL; - int want_lxc_log_specified = 0; if (lxc_log_fd != -1) return 0; @@ -209,30 +176,10 @@ extern int lxc_log_init(const char *name, const char *file, if (prefix) lxc_log_setprefix(prefix); - if (file && strcmp(file, "none") == 0) { - want_lxc_log_specified = 1; - return 0; - } - - if (!file) { - tmpfile = build_log_path(name); - if (!tmpfile) { - ERROR("could not build log path"); - return -1; - } - } else { - want_lxc_log_specified = 1; - } - - ret = lxc_log_set_file(tmpfile ? tmpfile : file); - - if (want_lxc_log_specified) - lxc_log_specified = 1; - - if (tmpfile) - free(tmpfile); + if (file) + return lxc_log_set_file(file); - return ret; + return 0; } /* @@ -255,23 +202,16 @@ extern int lxc_log_set_level(int level) char *log_fname; // default to NULL, set in lxc_log_set_file. /* - * This can be called: - * 1. when a program calls lxc_log_init with no logfile parameter (in which - * case the default is used). In this case lxc.logfile can override this. - * 2. when a program calls lxc_log_init with a logfile parameter. In this - * case we don't want lxc.logfile to override this. - * 3. When a lxc.logfile entry is found in config 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(const char *fname) { - if (lxc_log_specified) { - INFO("lxc.logfile overriden by command line"); - return 0; - } if (lxc_log_fd != -1) { - // we are overriding the default. - close(lxc_log_fd); - free(log_fname); + // this should've been caught at config_logfile. + ERROR("Race in setting logfile?"); + return -1; } lxc_log_fd = log_open(fname); diff --git a/src/lxc/log.h b/src/lxc/log.h index 771995865..a9260f22a 100644 --- a/src/lxc/log.h +++ b/src/lxc/log.h @@ -287,8 +287,8 @@ extern struct lxc_log_category lxc_log_category_lxc; extern int lxc_log_fd; -extern int lxc_log_init(const char *name, const char *file, - const char *priority, const char *prefix, int quiet); +extern int lxc_log_init(const char *file, const char *priority, + const char *prefix, int quiet); extern void lxc_log_setprefix(const char *a_prefix); extern int lxc_log_set_level(int level); diff --git a/src/lxc/lxc_attach.c b/src/lxc/lxc_attach.c index 437a40080..851a37aaa 100644 --- a/src/lxc/lxc_attach.c +++ b/src/lxc/lxc_attach.c @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) if (ret) return ret; - ret = lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + ret = lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet); if (ret) return ret; diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 970391ba2..97769a5a2 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) if (lxc_arguments_parse(&my_args, argc, argv)) return -1; - if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + if (lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet)) return -1; diff --git a/src/lxc/lxc_checkpoint.c b/src/lxc/lxc_checkpoint.c index a15175015..76f6709f2 100644 --- a/src/lxc/lxc_checkpoint.c +++ b/src/lxc/lxc_checkpoint.c @@ -115,7 +115,7 @@ int main(int argc, char *argv[]) if (ret) return ret; - ret = lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + ret = lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet); if (ret) return ret; diff --git a/src/lxc/lxc_console.c b/src/lxc/lxc_console.c index c263d0f81..d09c6882e 100644 --- a/src/lxc/lxc_console.c +++ b/src/lxc/lxc_console.c @@ -187,7 +187,7 @@ int main(int argc, char *argv[]) if (err) return -1; - err = lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + err = lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet); if (err) return -1; diff --git a/src/lxc/lxc_execute.c b/src/lxc/lxc_execute.c index 9377f4f31..1eb25a7da 100644 --- a/src/lxc/lxc_execute.c +++ b/src/lxc/lxc_execute.c @@ -99,7 +99,7 @@ int main(int argc, char *argv[]) if (lxc_arguments_parse(&my_args, argc, argv)) return -1; - if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + if (lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet)) return -1; diff --git a/src/lxc/lxc_freeze.c b/src/lxc/lxc_freeze.c index 4da565484..770d923ff 100644 --- a/src/lxc/lxc_freeze.c +++ b/src/lxc/lxc_freeze.c @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) if (lxc_arguments_parse(&my_args, argc, argv)) return -1; - if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + if (lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet)) return -1; diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c index 48c1370de..1a1cc22df 100644 --- a/src/lxc/lxc_info.c +++ b/src/lxc/lxc_info.c @@ -79,7 +79,7 @@ int main(int argc, char *argv[]) if (ret) return 1; - if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + if (lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet)) return 1; diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c index 90e1ad661..2263cd16f 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -79,7 +79,7 @@ int main(int argc, char *argv[]) if (lxc_caps_init()) exit(err); - if (lxc_log_init(NULL, "none", 0, basename(argv[0]), quiet)) + if (lxc_log_init(NULL, 0, basename(argv[0]), quiet)) exit(err); if (!argv[optind]) { diff --git a/src/lxc/lxc_kill.c b/src/lxc/lxc_kill.c index f9bfe34b6..3d996a5c7 100644 --- a/src/lxc/lxc_kill.c +++ b/src/lxc/lxc_kill.c @@ -61,7 +61,7 @@ int main(int argc, char *argv[], char *envp[]) if (ret) return ret; - ret = lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + ret = lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet); if (ret) return ret; diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c index 2b8b0a086..4bd6ab015 100644 --- a/src/lxc/lxc_monitor.c +++ b/src/lxc/lxc_monitor.c @@ -65,7 +65,7 @@ int main(int argc, char *argv[]) if (lxc_arguments_parse(&my_args, argc, argv)) return -1; - if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + if (lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet)) return -1; diff --git a/src/lxc/lxc_restart.c b/src/lxc/lxc_restart.c index 1cf9462e9..75486821c 100644 --- a/src/lxc/lxc_restart.c +++ b/src/lxc/lxc_restart.c @@ -122,7 +122,7 @@ int main(int argc, char *argv[]) if (lxc_arguments_parse(&my_args, argc, argv)) return -1; - if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + if (lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet)) return -1; diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c index b64acffe3..a97dccaa8 100644 --- a/src/lxc/lxc_start.c +++ b/src/lxc/lxc_start.c @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) else args = my_args.argv; - if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + if (lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet)) return err; diff --git a/src/lxc/lxc_stop.c b/src/lxc/lxc_stop.c index 749d78a65..639b7500b 100644 --- a/src/lxc/lxc_stop.c +++ b/src/lxc/lxc_stop.c @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) if (lxc_arguments_parse(&my_args, argc, argv)) return -1; - if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + if (lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet)) return -1; diff --git a/src/lxc/lxc_unfreeze.c b/src/lxc/lxc_unfreeze.c index 02e9a47c9..22be8395b 100644 --- a/src/lxc/lxc_unfreeze.c +++ b/src/lxc/lxc_unfreeze.c @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) if (lxc_arguments_parse(&my_args, argc, argv)) return -1; - if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + if (lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet)) return -1; diff --git a/src/lxc/lxc_wait.c b/src/lxc/lxc_wait.c index b0643c739..799225d97 100644 --- a/src/lxc/lxc_wait.c +++ b/src/lxc/lxc_wait.c @@ -83,7 +83,7 @@ int main(int argc, char *argv[]) if (lxc_arguments_parse(&my_args, argc, argv)) return -1; - if (lxc_log_init(my_args.name, my_args.log_file, my_args.log_priority, + if (lxc_log_init(my_args.log_file, my_args.log_priority, my_args.progname, my_args.quiet)) return -1; diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 502a7a73a..5919d2c57 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -976,7 +976,7 @@ struct lxc_container *lxc_container_new(const char *name) c->set_cgroup_item = lxcapi_set_cgroup_item; /* we'll allow the caller to update these later */ - if (lxc_log_init(NULL, "none", NULL, "lxc_container", 0)) { + if (lxc_log_init(NULL, NULL, "lxc_container", 0)) { fprintf(stderr, "failed to open log\n"); goto err; }