]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: Resolve /dev/console if it's connected to stdin
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 21 Mar 2025 09:39:46 +0000 (10:39 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 4 Apr 2025 15:13:14 +0000 (17:13 +0200)
If /dev/console is connected to stdin there's a possibility that
the unit might try to start a logind session from within the unit.
Let's make sure that any such sessions are started on the tty that
/dev/console points to and not on /dev/console itself.

src/core/exec-invoke.c

index d9878e608867216c0c8af2c94d4019d225599d34..0a29da522ed945665b697a8c73f6b5e1876728c7 100644 (file)
@@ -369,10 +369,21 @@ static int setup_input(
         case EXEC_INPUT_TTY_FORCE:
         case EXEC_INPUT_TTY_FAIL: {
                 _cleanup_close_ int tty_fd = -EBADF;
+                _cleanup_free_ char *resolved = NULL;
                 const char *tty_path;
 
                 tty_path = ASSERT_PTR(exec_context_tty_path(context));
 
+                if (tty_is_console(tty_path)) {
+                        r = resolve_dev_console(&resolved);
+                        if (r < 0)
+                                log_debug_errno(r, "Failed to resolve /dev/console, ignoring: %m");
+                        else {
+                                log_debug("Resolved /dev/console to %s", resolved);
+                                tty_path = resolved;
+                        }
+                }
+
                 tty_fd = acquire_terminal(tty_path,
                                           i == EXEC_INPUT_TTY_FAIL  ? ACQUIRE_TERMINAL_TRY :
                                           i == EXEC_INPUT_TTY_FORCE ? ACQUIRE_TERMINAL_FORCE :