From: Daan De Meyer Date: Fri, 21 Mar 2025 09:39:46 +0000 (+0100) Subject: core: Resolve /dev/console if it's connected to stdin X-Git-Tag: v258-rc1~901^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6f1d594d637fe47480aa001ee62d20306af8f38e;p=thirdparty%2Fsystemd.git 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. --- 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 :