[PATCH 3/5] dmesg: allow loglevels specified as numbers

Marco Felsch m.felsch at pengutronix.de
Mon Jun 12 23:41:04 PDT 2023


On 23-06-12, Sascha Hauer wrote:
> In Linux dmesg loglevels can be specified as strings or as numbers.
> Do likewise in barebox.
> 
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>

Reviewed-by: Marco Felsch <m.felsch at pengutronix.de>

> ---
>  commands/dmesg.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/commands/dmesg.c b/commands/dmesg.c
> index 2a36710b98..00e5a159e0 100644
> --- a/commands/dmesg.c
> +++ b/commands/dmesg.c
> @@ -13,6 +13,16 @@
>  
>  static int str_to_loglevel(const char *str)
>  {
> +	int ret;
> +	unsigned long level;
> +
> +	ret = kstrtoul(str, 10, &level);
> +	if (!ret) {
> +		if (level > MSG_VDEBUG)
> +			goto unknown;
> +		return level;
> +	}
> +
>  	if (!strcmp(str, "vdebug"))
>  		return MSG_VDEBUG;
>  	if (!strcmp(str, "debug"))
> @@ -31,7 +41,7 @@ static int str_to_loglevel(const char *str)
>  		return MSG_ALERT;
>  	if (!strcmp(str, "emerg"))
>  		return MSG_EMERG;
> -
> +unknown:
>  	printf("dmesg: unknown loglevel %s\n", str);
>  
>  	return -EINVAL;
> -- 
> 2.39.2
> 
> 
> 



More information about the barebox mailing list