We adopt static char* array (demon_status_msg) in daemon_status func, so it looks more simpler and easier to expand. Signed-off-by: Zhiqiang Liu <liuzhiqiang26@xxxxxxxxxx> Signed-off-by: lixiaokeng <lixiaokeng@xxxxxxxxxx> --- multipathd/main.c | 30 +++++++++++++++--------------- multipathd/main.h | 3 ++- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/multipathd/main.c b/multipathd/main.c index 9ec6585..cab1d0d 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -153,24 +153,24 @@ static volatile sig_atomic_t exit_sig; static volatile sig_atomic_t reconfig_sig; static volatile sig_atomic_t log_reset_sig; +static const char *demon_status_msg[DAEMON_STATUS_SIZE] = { + [DAEMON_INIT] = "init", + [DAEMON_START] = "startup", + [DAEMON_CONFIGURE] = "configure", + [DAEMON_IDLE] = "idle", + [DAEMON_RUNNING] = "running", + [DAEMON_SHUTDOWN] = "shutdown", +}; + const char * daemon_status(void) { - switch (get_running_state()) { - case DAEMON_INIT: - return "init"; - case DAEMON_START: - return "startup"; - case DAEMON_CONFIGURE: - return "configure"; - case DAEMON_IDLE: - return "idle"; - case DAEMON_RUNNING: - return "running"; - case DAEMON_SHUTDOWN: - return "shutdown"; - } - return NULL; + enum daemon_status status = get_running_state(); + + if (status < DAEMON_INIT || status >= DAEMON_STATUS_SIZE) + return NULL; + + return demon_status_msg[status]; } /* diff --git a/multipathd/main.h b/multipathd/main.h index 5dff17e..6a5592c 100644 --- a/multipathd/main.h +++ b/multipathd/main.h @@ -4,12 +4,13 @@ #define MAPGCINT 5 enum daemon_status { - DAEMON_INIT, + DAEMON_INIT = 0, DAEMON_START, DAEMON_CONFIGURE, DAEMON_IDLE, DAEMON_RUNNING, DAEMON_SHUTDOWN, + DAEMON_STATUS_SIZE, }; struct prout_param_descriptor; -- 1.8.3.1 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/dm-devel