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

Sascha Hauer s.hauer at pengutronix.de
Mon Jun 12 05:32:29 PDT 2023


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 at pengutronix.de>
---
 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;
 	}
 
 	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;
 			break;
 		case 'r':
 			flags |= BAREBOX_LOG_PRINT_RAW | BAREBOX_LOG_PRINT_TIME;
-- 
2.39.2




More information about the barebox mailing list