On Sun, 2020-08-16 at 09:42 +0800, Zhiqiang Liu wrote: > 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; I'd rather use "int" as the type of "status", because (not technically, but logically), an "enum daemon_status" cannot be outside this range. Martin -- dm-devel mailing list dm-devel@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/dm-devel