From 967bcc6e267aee6c95d9a6603b1c0a2ba27e1d1b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 15 Jul 2024 11:48:48 +0200 Subject: [PATCH] tree-wide: reset stdout not stdin We nowadays reset TTYs by writing ANSI sequences to them. This can only work if we operate on an *output* fd, not an input fd. Hence switch various cases where we erroneously used an input fd to use an output fd instead. --- src/core/execute.c | 4 ++-- src/firstboot/firstboot.c | 2 +- src/home/homectl.c | 2 +- src/test/test-terminal-util.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/execute.c b/src/core/execute.c index 7590943179b..6ed2f5a0f9d 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -147,8 +147,8 @@ void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p) const char *path = exec_context_tty_path(context); - if (p && p->stdin_fd >= 0 && isatty_safe(p->stdin_fd)) - fd = p->stdin_fd; + if (p && p->stdout_fd >= 0 && isatty_safe(p->stdout_fd)) + fd = p->stdout_fd; else if (path && (context->tty_path || is_terminal_input(context->std_input) || is_terminal_output(context->std_output) || is_terminal_output(context->std_error))) { fd = _fd = open_terminal(path, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK); diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 615142cc1ed..86aa8e8c181 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -133,7 +133,7 @@ static void print_welcome(int rfd) { pn = os_release_pretty_name(pretty_name, os_name); ac = isempty(ansi_color) ? "0" : ansi_color; - (void) terminal_reset_defensive(STDIN_FILENO, /* switch_to_text= */ false); + (void) terminal_reset_defensive(STDOUT_FILENO, /* switch_to_text= */ false); if (colors_enabled()) printf("\nWelcome to your new installation of \x1B[%sm%s\x1B[0m!\n", ac, pn); diff --git a/src/home/homectl.c b/src/home/homectl.c index c64354141c5..8022694f704 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -2438,7 +2438,7 @@ static int create_interactively(void) { (void) polkit_agent_open_if_enabled(arg_transport, arg_ask_password); - (void) terminal_reset_defensive(STDIN_FILENO, /* switch_to_text= */ false); + (void) terminal_reset_defensive(STDOUT_FILENO, /* switch_to_text= */ false); for (;;) { username = mfree(username); diff --git a/src/test/test-terminal-util.c b/src/test/test-terminal-util.c index e7cfeab6d00..68b9cbe6062 100644 --- a/src/test/test-terminal-util.c +++ b/src/test/test-terminal-util.c @@ -286,7 +286,7 @@ TEST(get_color_mode) { TEST(terminal_reset_defensive) { int r; - r = terminal_reset_defensive(STDIN_FILENO, /* switch_to_text= */ false); + r = terminal_reset_defensive(STDOUT_FILENO, /* switch_to_text= */ false); if (r < 0) log_notice_errno(r, "Failed to reset terminal: %m"); } -- 2.47.3