aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHangbin Liu <liuhangbin@gmail.com>2018-09-21 12:41:02 +0800
committerJiri Pirko <jiri@mellanox.com>2018-11-05 17:07:05 +0100
commite47d5db538736c74473842b57110b71d3844d7e6 (patch)
tree721248dcbd0140211e62bf57ea3894119629dd33
parentb6f63db7f3c8eb3119c9449abe9ac6535965e14d (diff)
downloadlibteam-e47d5db538736c74473842b57110b71d3844d7e6.tar.gz
teamd: add an option to force log output to stdout, stderr or syslog
By default, libdaemon prints the logs to stderr, and switches to syslog if the precess daemonizes. When some users, e.g. NetworkManager, run teamd foreground, the logs printed in syslog will as coming from NetworkManager, with mixed NetworkManager's own debug logs, which makes people feel a mess and hard to debug. Add option -l to support force teamd log output to stdout, stderr or syslog. Also add a global env TEAM_LOG_OUTPUT, which could be used for old version compatibility. Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
-rw-r--r--man/teamd.83
-rw-r--r--teamd/teamd.c18
-rw-r--r--teamd/teamd.h1
3 files changed, 21 insertions, 1 deletions
diff --git a/man/teamd.8 b/man/teamd.8
index 03b525c..3d27eae 100644
--- a/man/teamd.8
+++ b/man/teamd.8
@@ -69,6 +69,9 @@ Use the specified PID file.
.B "\-g, \-\-debug"
Turns on debugging messages. Repeating the option increases verbosity.
.TP
+.B "\-l, \-\-log-output"
+Force teamd log output to stdout, stderr or syslog.
+.TP
.B "\-r, \-\-force-recreate"
Force team device recreation in case it already exists.
.TP
diff --git a/teamd/teamd.c b/teamd/teamd.c
index aac2511..6c47312 100644
--- a/teamd/teamd.c
+++ b/teamd/teamd.c
@@ -107,6 +107,7 @@ static void print_help(const struct teamd_context *ctx) {
" file will be ignored)\n"
" -p --pid-file=FILE Use the specified PID file\n"
" -g --debug Increase verbosity\n"
+ " -l --log-output Force teamd log output to stdout, stderr or syslog\n"
" -r --force-recreate Force team device recreation in case it\n"
" already exists\n"
" -o --take-over Take over the device if it already exists\n"
@@ -140,6 +141,7 @@ static int parse_command_line(struct teamd_context *ctx,
{ "config", required_argument, NULL, 'c' },
{ "pid-file", required_argument, NULL, 'p' },
{ "debug", no_argument, NULL, 'g' },
+ { "log-output", required_argument, NULL, 'l' },
{ "force-recreate", no_argument, NULL, 'r' },
{ "take-over", no_argument, NULL, 'o' },
{ "no-quit-destroy", no_argument, NULL, 'N' },
@@ -152,7 +154,7 @@ static int parse_command_line(struct teamd_context *ctx,
{ NULL, 0, NULL, 0 }
};
- while ((opt = getopt_long(argc, argv, "hdkevf:c:p:groNt:nDZ:Uu",
+ while ((opt = getopt_long(argc, argv, "hdkevf:c:p:gl:roNt:nDZ:Uu",
long_options, NULL)) >= 0) {
switch(opt) {
@@ -191,6 +193,10 @@ static int parse_command_line(struct teamd_context *ctx,
case 'g':
ctx->debug++;
break;
+ case 'l':
+ free(ctx->log_output);
+ ctx->log_output = strdup(optarg);
+ break;
case 'r':
ctx->force_recreate = true;
break;
@@ -1494,6 +1500,16 @@ static int teamd_start(struct teamd_context *ctx, enum teamd_exit_code *p_ret)
/* Child */
}
+ ctx->log_output = ctx->log_output ? : getenv("TEAM_LOG_OUTPUT");
+ if (ctx->log_output) {
+ if (strcmp(ctx->log_output, "stdout") == 0)
+ daemon_log_use = DAEMON_LOG_STDOUT;
+ else if (strcmp(ctx->log_output, "stderr") == 0)
+ daemon_log_use = DAEMON_LOG_STDERR;
+ else if (strcmp(ctx->log_output, "syslog") == 0)
+ daemon_log_use = DAEMON_LOG_SYSLOG;
+ }
+
if (daemon_close_all(-1) < 0) {
teamd_log_err("Failed to close all file descriptors.");
daemon_retval_send(errno);
diff --git a/teamd/teamd.h b/teamd/teamd.h
index 3934fc2..01bd022 100644
--- a/teamd/teamd.h
+++ b/teamd/teamd.h
@@ -99,6 +99,7 @@ struct teamd_context {
enum teamd_command cmd;
bool daemonize;
unsigned int debug;
+ char * log_output;
bool force_recreate;
bool take_over;
bool no_quit_destroy;