From: 2xsec Date: Mon, 6 Aug 2018 03:50:31 +0000 (+0900) Subject: log: add default log priority X-Git-Tag: lxc-3.1.0~176^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03c6d26669e5c44f8de4189972132ecc987bafef;p=thirdparty%2Flxc.git log: add default log priority Signed-off-by: 2xsec --- diff --git a/src/lxc/log.c b/src/lxc/log.c index ec0a4be33..781295e5c 100644 --- a/src/lxc/log.c +++ b/src/lxc/log.c @@ -511,7 +511,7 @@ static int __lxc_log_set_file(const char *fname, int create_dirs) if (strlen(fname) == 0) { log_fname = NULL; - return 0; + return -1; } #if USE_CONFIGPATH_LOGS @@ -559,6 +559,9 @@ int lxc_log_init(struct lxc_log *log) int ret; int lxc_priority = LXC_LOG_LEVEL_ERROR; + if (!log) + return -1; + if (lxc_log_fd != -1) { WARN("Log already initialized"); return 0; @@ -572,10 +575,9 @@ int lxc_log_init(struct lxc_log *log) lxc_loglevel_specified = 1; } - if (!lxc_quiet_specified) { + if (!lxc_quiet_specified) if (!log->quiet) lxc_log_category_lxc.appender->next = &log_appender_stderr; - } if (log->prefix) lxc_log_set_prefix(log->prefix); @@ -588,6 +590,11 @@ int lxc_log_init(struct lxc_log *log) return 0; ret = __lxc_log_set_file(log->file, 1); + if (ret < 0) { + ERROR("Failed to enable logfile"); + return -1; + } + lxc_log_use_global_fd = 1; } else { /* if no name was specified, there nothing to do */ @@ -621,6 +628,11 @@ int lxc_log_init(struct lxc_log *log) ret = 0; } + if (lxc_log_fd != -1) { + lxc_log_category_lxc.appender = &log_appender_logfile; + lxc_log_category_lxc.appender->next = &log_appender_stderr; + } + return ret; } diff --git a/src/lxc/tools/arguments.c b/src/lxc/tools/arguments.c index 89af23c7f..f6ee123dc 100644 --- a/src/lxc/tools/arguments.c +++ b/src/lxc/tools/arguments.c @@ -192,6 +192,7 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, int argc, char *const argv[]) { int ret = 0; + bool logfile = false; char shortopts[256]; ret = build_shortopts(args->options, shortopts, sizeof(shortopts)); @@ -215,9 +216,14 @@ extern int lxc_arguments_parse(struct lxc_arguments *args, int argc, break; case 'o': args->log_file = optarg; + logfile = true; break; case 'l': args->log_priority = optarg; + if (!logfile && + args->log_file && + strcmp(args->log_file, "none") == 0) + args->log_file = NULL; break; case 'q': args->quiet = 1;