Re: [PATCH 2/5] dmesg: error out on unknown loglevels

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Sascha,

On 23-06-12, Sascha Hauer wrote:
> The user deserves an error when an unknown loglevel is given, so
> print an error instead of silently ignoring unknown loglevels.
> 
> Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
> ---
>  commands/dmesg.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/commands/dmesg.c b/commands/dmesg.c
> index 339910bb76..2a36710b98 100644
> --- a/commands/dmesg.c
> +++ b/commands/dmesg.c
> @@ -32,6 +32,8 @@ static int str_to_loglevel(const char *str)
>  	if (!strcmp(str, "emerg"))
>  		return MSG_EMERG;
>  
> +	printf("dmesg: unknown loglevel %s\n", str);
> +
>  	return -EINVAL;
>  }
>  
> @@ -51,6 +53,8 @@ static unsigned dmesg_get_levels(const char *__args)
>  		level = str_to_loglevel(str);
>  		if (level >= 0)
>  			flags |= BIT(level);
> +		else
> +			return 0;

This is more explicit but wouldn't be required since we initialized
'flags = 0'.

>  	}
>  
>  	free(args);
> @@ -81,7 +85,7 @@ static int do_dmesg(int argc, char *argv[])
>  		case 'l':
>  			levels = dmesg_get_levels(optarg);
>  			if (!levels)
> -				return COMMAND_ERROR_USAGE;
> +				return COMMAND_ERROR;

Out of curiosity what's the difference between COMMAND_ERROR and
COMMAND_ERROR_USAGE?

Regards,
  Marco

>  			break;
>  		case 'r':
>  			flags |= BAREBOX_LOG_PRINT_RAW | BAREBOX_LOG_PRINT_TIME;
> -- 
> 2.39.2
> 
> 
> 




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux