From daf13202373e4723aa11f0565468dc7b7cf420f5 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 25 Jan 2025 20:19:26 +0100 Subject: [PATCH] terminal-util: make get_kernel_consoles() return > 0 if /dev/console is resolved --- src/basic/terminal-util.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 2baf2830b17..678cd4ed4dd 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -866,13 +866,12 @@ int resolve_dev_console(char **ret) { int get_kernel_consoles(char ***ret) { _cleanup_strv_free_ char **l = NULL; _cleanup_free_ char *line = NULL; - const char *p; int r; assert(ret); - /* If /sys is mounted read-only this means we are running in some kind of container environment. In that - * case /sys would reflect the host system, not us, hence ignore the data we can read from it. */ + /* If /sys/ is mounted read-only this means we are running in some kind of container environment. + * In that case /sys/ would reflect the host system, not us, hence ignore the data we can read from it. */ if (path_is_read_only_fs("/sys") > 0) goto fallback; @@ -880,8 +879,7 @@ int get_kernel_consoles(char ***ret) { if (r < 0) return r; - p = line; - for (;;) { + for (const char *p = line;;) { _cleanup_free_ char *tty = NULL, *path = NULL; r = extract_first_word(&p, &tty, NULL, 0); @@ -917,8 +915,7 @@ int get_kernel_consoles(char ***ret) { } *ret = TAKE_PTR(l); - - return 0; + return strv_length(*ret); fallback: r = strv_extend(&l, "/dev/console"); @@ -926,7 +923,6 @@ fallback: return r; *ret = TAKE_PTR(l); - return 0; } -- 2.47.3