From patchwork Fri Sep 21 04:41:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hangbin Liu X-Patchwork-Id: 10609055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 188216CB for ; Fri, 21 Sep 2018 04:41:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07A012DC90 for ; Fri, 21 Sep 2018 04:41:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE81A2DC9A; Fri, 21 Sep 2018 04:41:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from bastion.fedoraproject.org (bastion01.fedoraproject.org [209.132.181.2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 72D5A2DC90 for ; Fri, 21 Sep 2018 04:41:31 +0000 (UTC) Received: from mailman01.phx2.fedoraproject.org (mailman01.phx2.fedoraproject.org [10.5.126.36]) by bastion01.phx2.fedoraproject.org (Postfix) with ESMTP id B9FD5608F472; Fri, 21 Sep 2018 04:41:30 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 bastion01.phx2.fedoraproject.org B9FD5608F472 Received: from mailman01.phx2.fedoraproject.org (localhost [IPv6:::1]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id A50C6239E69FB; Fri, 21 Sep 2018 04:41:30 +0000 (UTC) Received: by mailman01.phx2.fedoraproject.org (Postfix, from userid 991) id F273E239E4653; Fri, 21 Sep 2018 04:41:26 +0000 (UTC) Received: from smtp-mm-ib01.fedoraproject.org (smtp-mm-ib01.vpn.fedoraproject.org [192.168.1.83]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 0273F239E4640 for ; Fri, 21 Sep 2018 04:41:25 +0000 (UTC) Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by smtp-mm-ib01.fedoraproject.org (Postfix) with ESMTPS id 77658605D2DA for ; Fri, 21 Sep 2018 04:41:24 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id j8-v6so5343967pll.12 for ; Thu, 20 Sep 2018 21:41:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=cy1pYHNDhgII9NC97AWUjbBcnbk91DM3AhNQbOWIJak=; b=jb/0mhIX3LVZw0hypDrsHAGrPP66xubiD1+j+82fGZjiBm8yaAZ1jkoKHSwbHVXMyy gR1LMtKTpWv2mmH+TtGR+YU5bRZ5KkEBtTXjFkaADvBl5qduEqcMof0wjfgzSP0NvGOO tkQObF/Df4AQ5Y0y1cG/PKcSm9WYaeb5uH+UhAJBhPayfa2tB9ZPR/ZD4bYZzdHQlk/y 5HsKRezS2XXXwZ9FNqWNcl7lTU1Dji99tK7GR7uIXSx4VdHtWNgvZJqLOoYXl5mR04FH pTlQVdDZ16N04wC4zbXDg/u5LFQYkocIakWI5259lYQEBi4JTHHhCHyi4zpjz4wOgjhA l0Gw== X-Gm-Message-State: APzg51AuYzIK8O2lTNTWYSyjais+tEnzKIyJINinHPBEsaGe2beXhZWU gF3sWazv5zmn/tn8ahXssK+BVfWD X-Google-Smtp-Source: ANB0VdbajoU73AeurYH0OLvaYe5m2HQM3hLBcfvUgEo68OWFlmf93TbtFocygC53b6/BCokjwLlHdg== X-Received: by 2002:a17:902:bccb:: with SMTP id o11-v6mr42141564pls.167.1537504880105; Thu, 20 Sep 2018 21:41:20 -0700 (PDT) Received: from leo.usersys.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id g15-v6sm44416502pfg.98.2018.09.20.21.41.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 21:41:19 -0700 (PDT) From: Hangbin Liu To: libteam@lists.fedorahosted.org Subject: [PATCH] teamd: add an option to force log output to stdout, stderr or syslog Date: Fri, 21 Sep 2018 12:41:02 +0800 Message-Id: <1537504862-1904-1-git-send-email-liuhangbin@gmail.com> X-Mailer: git-send-email 2.5.5 Message-ID-Hash: 6YQGAIZFSXWBXZWQ7O7XAB25V3B42HRT X-Message-ID-Hash: 6YQGAIZFSXWBXZWQ7O7XAB25V3B42HRT X-MailFrom: liuhangbin@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Jamie Bainbridge , Jiri Pirko , Hangbin Liu X-Mailman-Version: 3.1.1 Precedence: list List-Id: Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP 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 --- man/teamd.8 | 3 +++ teamd/teamd.c | 18 +++++++++++++++++- teamd/teamd.h | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) 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;