All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhiqiang Liu <liuzhiqiang26@huawei.com>
To: mwilck@suse.com, Benjamin Marzinski <bmarzins@redhat.com>,
	Christophe Varoqui <christophe.varoqui@opensvc.com>,
	Zdenek Kabelac <zkabelac@redhat.com>
Cc: linfeilong <linfeilong@huawei.com>,
	Yanxiaodan <yanxiaodan@huawei.com>,
	dm-devel@redhat.com, lixiaokeng <lixiaokeng@huawei.com>,
	liuzhiqiang26@huawei.com
Subject: [PATCH V2 2/5] multipathd: use daemon_status_msg to construct sd notify msg in do_sd_notify func
Date: Fri, 21 Aug 2020 18:59:20 +0800	[thread overview]
Message-ID: <8e3e5a81-dcd5-b3d5-41c7-2f443b854367@huawei.com> (raw)
In-Reply-To: <52b3b834-6da6-99c1-a2d1-95c2387c47e3@huawei.com>


sd_notify_status() is very similar with daemon_status(), except
DAEMON_IDLE and DAEMON_RUNNING state. As suggested by Martin,
we can create the sd notification string in a dynamic buffer,
and treat DAEMON_IDLE and DAEMON_RUNNING cases first. Then,
we can use daemon_status_msg[state] for other cases.

Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: lixiaokeng <lixiaokeng@huawei.com>
---
 multipathd/main.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/multipathd/main.c b/multipathd/main.c
index 62cf4ff4..4ba015bb 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -85,6 +85,7 @@

 #define FILE_NAME_SIZE 256
 #define CMDSIZE 160
+#define MSG_SIZE 64

 #define LOG_MSG(lvl, verb, pp)					\
 do {								\
@@ -177,28 +178,12 @@ daemon_status(void)
  * I love you too, systemd ...
  */
 #ifdef USE_SYSTEMD
-static const char *
-sd_notify_status(enum daemon_status state)
-{
-	switch (state) {
-	case DAEMON_INIT:
-		return "STATUS=init";
-	case DAEMON_START:
-		return "STATUS=startup";
-	case DAEMON_CONFIGURE:
-		return "STATUS=configure";
-	case DAEMON_IDLE:
-	case DAEMON_RUNNING:
-		return "STATUS=up";
-	case DAEMON_SHUTDOWN:
-		return "STATUS=shutdown";
-	}
-	return NULL;
-}
-
 static void do_sd_notify(enum daemon_status old_state,
 			 enum daemon_status new_state)
 {
+	char notify_msg[MSG_SIZE];
+	const char prefix[] = "STATUS=";
+	const char *msg = NULL;
 	/*
 	 * Checkerloop switches back and forth between idle and running state.
 	 * No need to tell systemd each time.
@@ -207,7 +192,18 @@ static void do_sd_notify(enum daemon_status old_state,
 	if ((new_state == DAEMON_IDLE || new_state == DAEMON_RUNNING) &&
 	    (old_state == DAEMON_IDLE || old_state == DAEMON_RUNNING))
 		return;
-	sd_notify(0, sd_notify_status(new_state));
+
+	if (new_state == DAEMON_IDLE || new_state == DAEMON_RUNNING)
+		msg = "up";
+	else
+		msg = daemon_status_msg[new_state];
+
+	if (snprintf(notify_msg, MSG_SIZE, "%s%s", prefix, msg) >= MSG_SIZE) {
+		condlog(2, "len of msg is should be shorter than %d", MSG_SIZE);
+		return;
+	}
+
+	sd_notify(0, notify_msg);
 }
 #endif

-- 
2.24.0.windows.2

  parent reply	other threads:[~2020-08-21 10:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-21 10:57 [PATCH V2 0/5] multipath-tools series: some cleanups and fixes Zhiqiang Liu
2020-08-21 10:58 ` [PATCH V2 1/5] multipathd: adopt static char* arr in daemon_status Zhiqiang Liu
2020-08-21 11:07   ` Martin Wilck
2020-08-21 13:42   ` Martin Wilck
2020-08-22  4:31     ` Zhiqiang Liu
2020-08-21 10:59 ` Zhiqiang Liu [this message]
2020-08-21 11:12   ` [PATCH V2 2/5] multipathd: use daemon_status_msg to construct sd notify msg in do_sd_notify func Martin Wilck
2020-08-21 11:00 ` [PATCH V2 3/5] libmultipath: check blist before calling MALLOC in alloc_ble_device func Zhiqiang Liu
2020-08-21 11:15   ` Martin Wilck
2020-08-21 11:00 ` [PATCH V2 4/5] vector: add lower boundary check in vector_foreach_slot_after Zhiqiang Liu
2020-08-21 11:20   ` Martin Wilck
2020-08-21 11:01 ` [PATCH V2 5/5] multipathd: remove useless memset after MALLOC in alloc_waiteri func Zhiqiang Liu
2020-08-21 11:18   ` Martin Wilck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8e3e5a81-dcd5-b3d5-41c7-2f443b854367@huawei.com \
    --to=liuzhiqiang26@huawei.com \
    --cc=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@redhat.com \
    --cc=linfeilong@huawei.com \
    --cc=lixiaokeng@huawei.com \
    --cc=mwilck@suse.com \
    --cc=yanxiaodan@huawei.com \
    --cc=zkabelac@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.