On 2020/8/17 16:23, Martin Wilck wrote:
> 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 <liuzhiqian...@huawei.com>
>> Signed-off-by: lixiaokeng <lixiaok...@huawei.com>
>> ---
>>  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
> 
Thanks for your suggestion.
I will use 'int' as the type of 'status' in v2 patch.

Zhiqiang Liu
> 
> 
> .
> 

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel

Reply via email to