From 6f1d594d637fe47480aa001ee62d20306af8f38e Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 21 Mar 2025 10:39:46 +0100 Subject: [PATCH] core: Resolve /dev/console if it's connected to stdin 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 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index d9878e60886..0a29da522ed 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -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 : -- 2.47.3