]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: make get_kernel_consoles() return > 0 if /dev/console is resolved
authorMike Yuan <me@yhndnzj.com>
Sat, 25 Jan 2025 19:19:26 +0000 (20:19 +0100)
committerMike Yuan <me@yhndnzj.com>
Sun, 26 Jan 2025 03:15:41 +0000 (04:15 +0100)
src/basic/terminal-util.c

index 2baf2830b176cced3ea81bc2e73c547094fcd520..678cd4ed4dd4f54262aabfaa6412aeb6342bc9b0 100644 (file)
@@ -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;
 }