From patchwork Tue Aug 7 13:17:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 10558711 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 97A70174A for ; Tue, 7 Aug 2018 13:18:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82C2F29D86 for ; Tue, 7 Aug 2018 13:18:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 721BF29DBB; Tue, 7 Aug 2018 13:18:09 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (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 34F3829D86 for ; Tue, 7 Aug 2018 13:18:09 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1AF07210DF4E7; Tue, 7 Aug 2018 06:18:09 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=202.219.69.169; helo=mgwkm02.jp.fujitsu.com; envelope-from=qi.fuli@jp.fujitsu.com; receiver=linux-nvdimm@lists.01.org Received: from mgwkm02.jp.fujitsu.com (mgwkm02.jp.fujitsu.com [202.219.69.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7C628210DC1BF for ; Tue, 7 Aug 2018 06:18:07 -0700 (PDT) Received: from kw-mxoi2.gw.nic.fujitsu.com (unknown [192.168.231.133]) by mgwkm02.jp.fujitsu.com with smtp id 5051_3d76_7071166b_1a90_4edf_8ca5_cacec16ea7dd; Tue, 07 Aug 2018 22:18:04 +0900 Received: from m3051.s.css.fujitsu.com (m3051.s.css.fujitsu.com [10.134.21.209]) by kw-mxoi2.gw.nic.fujitsu.com (Postfix) with ESMTP id 975DAAC00FD for ; Tue, 7 Aug 2018 22:18:03 +0900 (JST) Received: from localhost.localdomain (unknown [10.124.196.110]) by m3051.s.css.fujitsu.com (Postfix) with ESMTP id 6F9A0166; Tue, 7 Aug 2018 22:18:03 +0900 (JST) From: QI Fuli To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 1/4] ndctl, monitor: fix the lack of detection of invalid path of log file Date: Tue, 7 Aug 2018 22:17:53 +0900 Message-Id: <20180807131756.23673-2-qi.fuli@jp.fujitsu.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180807131756.23673-1-qi.fuli@jp.fujitsu.com> References: <20180807131756.23673-1-qi.fuli@jp.fujitsu.com> X-TM-AS-MML: disable X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Currently the monitor can be started even with an invalid path of log file. This patch adds a detection of invalid path of log file when starting monitor. If the path of log file is invalid, the monitor will refuse to be started. Signed-off-by: QI Fuli --- ndctl/monitor.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ndctl/monitor.c b/ndctl/monitor.c index f10384b..bf1f1d3 100644 --- a/ndctl/monitor.c +++ b/ndctl/monitor.c @@ -603,6 +603,7 @@ int cmd_monitor(int argc, const char **argv, void *ctx) struct util_filter_ctx fctx = { 0 }; struct monitor_filter_arg mfa = { 0 }; int i, rc; + FILE *f; argc = parse_options_prefix(argc, argv, prefix, options, u, 0); for (i = 0; i < argc; i++) { @@ -630,8 +631,16 @@ int cmd_monitor(int argc, const char **argv, void *ctx) ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_syslog); else if (strncmp(monitor.log, "./standard", 10) == 0) ; /*default, already set */ - else + else { + f = fopen(monitor.log, "a+"); + if (!f) { + error("open %s failed\n", monitor.log); + rc = -errno; + goto out; + } + fclose(f); ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_file); + } } if (monitor.daemon) { From patchwork Tue Aug 7 13:17:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 10558713 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 B96C813AC for ; Tue, 7 Aug 2018 13:18:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A787D29D86 for ; Tue, 7 Aug 2018 13:18:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BDEF29DBB; Tue, 7 Aug 2018 13:18:12 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (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 4C3AE29D86 for ; Tue, 7 Aug 2018 13:18:12 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3456D210DF4EC; Tue, 7 Aug 2018 06:18:12 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=202.219.69.168; helo=mgwkm01.jp.fujitsu.com; envelope-from=qi.fuli@jp.fujitsu.com; receiver=linux-nvdimm@lists.01.org Received: from mgwkm01.jp.fujitsu.com (mgwkm01.jp.fujitsu.com [202.219.69.168]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 338D1210DF4EB for ; Tue, 7 Aug 2018 06:18:09 -0700 (PDT) Received: from kw-mxauth.gw.nic.fujitsu.com (unknown [192.168.231.132]) by mgwkm01.jp.fujitsu.com with smtp id 12a7_368a_18888825_c973_4e21_a34e_cea6ee2cfc38; Tue, 07 Aug 2018 22:18:05 +0900 Received: from m3051.s.css.fujitsu.com (m3051.s.css.fujitsu.com [10.134.21.209]) by kw-mxauth.gw.nic.fujitsu.com (Postfix) with ESMTP id B87C2AC008D for ; Tue, 7 Aug 2018 22:18:04 +0900 (JST) Received: from localhost.localdomain (unknown [10.124.196.110]) by m3051.s.css.fujitsu.com (Postfix) with ESMTP id 96661166; Tue, 7 Aug 2018 22:18:04 +0900 (JST) From: QI Fuli To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 2/4] ndctl, monitor: set default log destination to syslog if "--daemon" is specified Date: Tue, 7 Aug 2018 22:17:54 +0900 Message-Id: <20180807131756.23673-3-qi.fuli@jp.fujitsu.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180807131756.23673-1-qi.fuli@jp.fujitsu.com> References: <20180807131756.23673-1-qi.fuli@jp.fujitsu.com> X-TM-AS-MML: disable X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP When running monitor as a daemon, if the log destination is "standard" or a relative path for log file, the messages will not be able to be logged. Sometimes, users may not notice that the default log destination is "standard" when they start monitor daemon by systemctl, so they will lose messages. This patch is used to fix the unfriendly interface. When running monitor as a daemon, the default log destination will be changed to syslog. Also, the messages will be forwarded to syslog if the log destination is a relative path for log file. Signed-off-by: QI Fuli --- Documentation/ndctl/ndctl-monitor.txt | 16 +++++++++++++++- ndctl/monitor.c | 5 ++++- ndctl/monitor.conf | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Documentation/ndctl/ndctl-monitor.txt b/Documentation/ndctl/ndctl-monitor.txt index 1cba9ea..9a8d76b 100644 --- a/Documentation/ndctl/ndctl-monitor.txt +++ b/Documentation/ndctl/ndctl-monitor.txt @@ -67,7 +67,21 @@ OPTIONS -l :: --log=:: - Output notifications to , syslog or standard output. + Send log messages to the specified destination. ++ +-- +:: + Send log messages to specified . When fopen() is not able + to open , log messages will be forwarded to syslog. +syslog:: + Send messages to syslog. +standard:: + Send messages to standard output. +-- ++ +The default log destination is 'syslog' if "--daemon" is specified, +otherwise 'standard'. Note that standard and relative path for +will not work if "--daemon" is specified. -c:: --config-file=:: diff --git a/ndctl/monitor.c b/ndctl/monitor.c index bf1f1d3..2f3d751 100644 --- a/ndctl/monitor.c +++ b/ndctl/monitor.c @@ -93,7 +93,8 @@ static void log_file(struct ndctl_ctx *ctx, int priority, const char *file, f = fopen(monitor.log, "a+"); if (!f) { ndctl_set_log_fn(ctx, log_syslog); - err(ctx, "open logfile %s failed\n", monitor.log); + err(ctx, "open logfile %s failed, forward messages to syslog\n", + monitor.log); did_fail = 1; notice(ctx, "%s\n", buf); goto end; @@ -644,6 +645,8 @@ int cmd_monitor(int argc, const char **argv, void *ctx) } if (monitor.daemon) { + if (!monitor.log || strncmp(monitor.log, "./", 2) == 0) + ndctl_set_log_fn((struct ndctl_ctx *)ctx, log_syslog); if (daemon(0, 0) != 0) { err((struct ndctl_ctx *)ctx, "daemon start failed\n"); goto out; diff --git a/ndctl/monitor.conf b/ndctl/monitor.conf index 857aadf..934e2c0 100644 --- a/ndctl/monitor.conf +++ b/ndctl/monitor.conf @@ -38,4 +38,6 @@ # to standard output (log=standard) or to write into a special file (log=) # by setting key "log". If this value is in conflict with the value of # [--log=] option, this value will be ignored. +# Note: Setting value to "standard" or relative path for will not work +# when running moniotr as a daemon. # log = /var/log/ndctl/monitor.log From patchwork Tue Aug 7 13:17:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 10558715 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 C207813AC for ; Tue, 7 Aug 2018 13:18:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9FA229D86 for ; Tue, 7 Aug 2018 13:18:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92C5229DBB; Tue, 7 Aug 2018 13:18:13 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (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 5152F29D86 for ; Tue, 7 Aug 2018 13:18:13 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 499D2210DF4F0; Tue, 7 Aug 2018 06:18:13 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=202.219.69.169; helo=mgwkm02.jp.fujitsu.com; envelope-from=qi.fuli@jp.fujitsu.com; receiver=linux-nvdimm@lists.01.org Received: from mgwkm02.jp.fujitsu.com (mgwkm02.jp.fujitsu.com [202.219.69.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2C103210DC1DB for ; Tue, 7 Aug 2018 06:18:11 -0700 (PDT) Received: from kw-mxoi2.gw.nic.fujitsu.com (unknown [192.168.231.133]) by mgwkm02.jp.fujitsu.com with smtp id 5051_3d7e_a22d9759_9a2c_4562_a453_5ea6a3a227e3; Tue, 07 Aug 2018 22:18:06 +0900 Received: from m3051.s.css.fujitsu.com (m3051.s.css.fujitsu.com [10.134.21.209]) by kw-mxoi2.gw.nic.fujitsu.com (Postfix) with ESMTP id E87DEAC00FD for ; Tue, 7 Aug 2018 22:18:05 +0900 (JST) Received: from localhost.localdomain (unknown [10.124.196.110]) by m3051.s.css.fujitsu.com (Postfix) with ESMTP id C153C166; Tue, 7 Aug 2018 22:18:05 +0900 (JST) From: QI Fuli To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 3/4] ndctl, monitor: add timestamp and pid to log messages in log_file() Date: Tue, 7 Aug 2018 22:17:55 +0900 Message-Id: <20180807131756.23673-4-qi.fuli@jp.fujitsu.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180807131756.23673-1-qi.fuli@jp.fujitsu.com> References: <20180807131756.23673-1-qi.fuli@jp.fujitsu.com> X-TM-AS-MML: disable X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP This patch is used to add timestamp and process id to log messages when logging messages to a file. Signed-off-by: QI Fuli --- ndctl/monitor.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ndctl/monitor.c b/ndctl/monitor.c index 2f3d751..d29e378 100644 --- a/ndctl/monitor.c +++ b/ndctl/monitor.c @@ -84,6 +84,8 @@ static void log_file(struct ndctl_ctx *ctx, int priority, const char *file, { FILE *f; char *buf; + struct timespec ts; + char timestamp[32]; if (vasprintf(&buf, format, args) < 0) { fail("vasprintf error\n"); @@ -99,7 +101,14 @@ static void log_file(struct ndctl_ctx *ctx, int priority, const char *file, notice(ctx, "%s\n", buf); goto end; } - fprintf(f, "%s", buf); + + if (priority != LOG_NOTICE) { + clock_gettime(CLOCK_REALTIME, &ts); + sprintf(timestamp, "%10ld.%09ld", ts.tv_sec, ts.tv_nsec); + fprintf(f, "[%s] [%d] %s", timestamp, getpid(), buf); + } else + fprintf(f, "%s", buf); + fflush(f); fclose(f); end: From patchwork Tue Aug 7 13:17:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 10558717 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 D61BF15E9 for ; Tue, 7 Aug 2018 13:18:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C490A29D86 for ; Tue, 7 Aug 2018 13:18:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B90AE29DBB; Tue, 7 Aug 2018 13:18:16 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (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 7EC3429D86 for ; Tue, 7 Aug 2018 13:18:16 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 60DDA210DF4F4; Tue, 7 Aug 2018 06:18:16 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=202.219.69.170; helo=mgwkm03.jp.fujitsu.com; envelope-from=qi.fuli@jp.fujitsu.com; receiver=linux-nvdimm@lists.01.org Received: from mgwkm03.jp.fujitsu.com (mgwkm03.jp.fujitsu.com [202.219.69.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3D615210DC1BF for ; Tue, 7 Aug 2018 06:18:13 -0700 (PDT) Received: from kw-mxoi1.gw.nic.fujitsu.com (unknown [192.168.231.131]) by mgwkm03.jp.fujitsu.com with smtp id 7942_5bde_716540f3_a6d2_4142_aee4_576405ba3176; Tue, 07 Aug 2018 22:18:07 +0900 Received: from m3051.s.css.fujitsu.com (m3051.s.css.fujitsu.com [10.134.21.209]) by kw-mxoi1.gw.nic.fujitsu.com (Postfix) with ESMTP id 01813AC00A4 for ; Tue, 7 Aug 2018 22:18:07 +0900 (JST) Received: from localhost.localdomain (unknown [10.124.196.110]) by m3051.s.css.fujitsu.com (Postfix) with ESMTP id CD0F9172; Tue, 7 Aug 2018 22:18:06 +0900 (JST) From: QI Fuli To: linux-nvdimm@lists.01.org Subject: [ndctl PATCH 4/4] ndctl, monitor: add [Install] Section to systemd unit file of ndctl-monitor Date: Tue, 7 Aug 2018 22:17:56 +0900 Message-Id: <20180807131756.23673-5-qi.fuli@jp.fujitsu.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180807131756.23673-1-qi.fuli@jp.fujitsu.com> References: <20180807131756.23673-1-qi.fuli@jp.fujitsu.com> X-TM-AS-MML: disable X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP This patch is used to add "[Install]" section to systemd unit file of ndctl-monitor. Therefore, users can set ndctl-monitor unit enable. Signed-off-by: QI Fuli --- ndctl/ndctl-monitor.service | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ndctl/ndctl-monitor.service b/ndctl/ndctl-monitor.service index 44f9326..342a1b1 100644 --- a/ndctl/ndctl-monitor.service +++ b/ndctl/ndctl-monitor.service @@ -5,3 +5,6 @@ Description=Ndctl Monitor Daemon Type=forking ExecStart=/usr/bin/ndctl monitor --daemon ExecStop=/bin/kill ${MAINPID} + +[Install] +WantedBy=multi-user.target