]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: handle the case where no system console is active
authorMike Yuan <me@yhndnzj.com>
Fri, 6 Feb 2026 01:07:05 +0000 (02:07 +0100)
committerMike Yuan <me@yhndnzj.com>
Tue, 10 Feb 2026 21:04:02 +0000 (22:04 +0100)
/dev/console might have no backing driver, in which case
/sys/class/tty/console/active is empty. Unlike get_kernel_consoles()
resolve_dev_console() currently proceeds with empty devnode,
resulting in setup_input() -> acquire_terminal() emitting -EISDIR
as we're trying to open /dev/. Let's catch this and report -ENXIO.

src/basic/terminal-util.c

index 01c2bd375053b72b1b36809b97b3ab531cc608ec..91ef5d7c0777730bc119190538325dfa6e325729 100644 (file)
@@ -1116,7 +1116,7 @@ int resolve_dev_console(char **ret) {
          * is a sign for container setups). */
 
         _cleanup_free_ char *chased = NULL;
-        r = chase("/dev/console", /* root= */ NULL, /* flags= */ 0,  &chased, /* ret_fd= */ NULL);
+        r = chase("/dev/console", /* root= */ NULL, /* flags= */ 0, &chased, /* ret_fd= */ NULL);
         if (r < 0)
                 return r;
         if (!path_equal(chased, "/dev/console")) {
@@ -1134,6 +1134,8 @@ int resolve_dev_console(char **ret) {
         r = read_one_line_file("/sys/class/tty/console/active", &active);
         if (r < 0)
                 return r;
+        if (r == 0)
+                return -ENXIO;
 
         /* If multiple log outputs are configured the last one is what /dev/console points to */
         const char *tty = strrchr(active, ' ');