From patchwork Thu Jul 19 08:54:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 10533925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E97ED600D0 for ; Thu, 19 Jul 2018 08:55:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9BC2295DE for ; Thu, 19 Jul 2018 08:55:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDE9C295E1; Thu, 19 Jul 2018 08:55:19 +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 684DE2957C for ; Thu, 19 Jul 2018 08:55:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 281C72098C8CB; Thu, 19 Jul 2018 01:55:19 -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 E27E121BADAB2 for ; Thu, 19 Jul 2018 01:55:17 -0700 (PDT) Received: from kw-mxoi2.gw.nic.fujitsu.com (unknown [192.168.231.133]) by mgwkm02.jp.fujitsu.com with smtp id 48f2_e7f1_4d73ebcd_052f_4e05_b4d2_53483e74e27b; Thu, 19 Jul 2018 17:55:11 +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 9DDFAAC01EF for ; Thu, 19 Jul 2018 17:55:10 +0900 (JST) Received: from qi-fedora.fujitsu.com (unknown [10.124.196.110]) by m3051.s.css.fujitsu.com (Postfix) with ESMTP id 7DFC3240; Thu, 19 Jul 2018 17:55:10 +0900 (JST) From: QI Fuli To: linux-nvdimm@lists.01.org Subject: [PATCH] ndctl, monitor: fix monitor can be started though no dimm event to monitor Date: Thu, 19 Jul 2018 17:54:27 +0900 Message-Id: <20180719085427.17836-1-qi.fuli@jp.fujitsu.com> X-Mailer: git-send-email 2.18.0 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 still can be started though there is no dimm event to be monitored, which is caused by the typo of uses. In this case, no smart event message can be logged. This patch is used to fix this bug. When user starts the monitor with invalid dimm event in [--dimm-event] option, the monitor will stop and output error message. Signed-off-by: QI Fuli --- ndctl/monitor.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ndctl/monitor.c b/ndctl/monitor.c index 8300250..abab45f 100644 --- a/ndctl/monitor.c +++ b/ndctl/monitor.c @@ -413,7 +413,7 @@ static int monitor_event(struct ndctl_ctx *ctx, return 0; } -static int parse_monitor_event(struct monitor *_monitor) +static int parse_monitor_event(struct monitor *_monitor, struct ndctl_ctx *ctx) { char *dimm_event, *save; const char *event; @@ -432,14 +432,18 @@ static int parse_monitor_event(struct monitor *_monitor) } if (strcmp(event, "dimm-spares-remaining") == 0) _monitor->event_flags |= ND_EVENT_SPARES_REMAINING; - if (strcmp(event, "dimm-media-temperature") == 0) + else if (strcmp(event, "dimm-media-temperature") == 0) _monitor->event_flags |= ND_EVENT_MEDIA_TEMPERATURE; - if (strcmp(event, "dimm-controller-temperature") == 0) + else if (strcmp(event, "dimm-controller-temperature") == 0) _monitor->event_flags |= ND_EVENT_CTRL_TEMPERATURE; - if (strcmp(event, "dimm-health-state") == 0) + else if (strcmp(event, "dimm-health-state") == 0) _monitor->event_flags |= ND_EVENT_HEALTH_STATE; - if (strcmp(event, "dimm-unclean-shutdown") == 0) + else if (strcmp(event, "dimm-unclean-shutdown") == 0) _monitor->event_flags |= ND_EVENT_UNCLEAN_SHUTDOWN; + else { + err(ctx, "no dimm-event named %s\n", event); + return 1; + } } free(dimm_event); @@ -620,7 +624,7 @@ int cmd_monitor(int argc, const char **argv, void *ctx) notice((struct ndctl_ctx *)ctx, "ndctl monitor daemon started\n"); } - if (parse_monitor_event(&monitor)) + if (parse_monitor_event(&monitor, (struct ndctl_ctx *)ctx)) goto out; fctx.filter_bus = filter_bus;