]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: reset stdout not stdin
authorLennart Poettering <lennart@poettering.net>
Mon, 15 Jul 2024 09:48:48 +0000 (11:48 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 19 Jul 2024 09:44:04 +0000 (11:44 +0200)
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
src/firstboot/firstboot.c
src/home/homectl.c
src/test/test-terminal-util.c

index 7590943179b5bec3c9e3c6d8f17b1456ba5e20f4..6ed2f5a0f9d6560356afe35391f5b888400acbb4 100644 (file)
@@ -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);
index 615142cc1edb075694962a64aa284045fa4e1eb0..86aa8e8c181b33f6cf055a5fcb0900fc64d3be31 100644 (file)
@@ -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);
index c64354141c57b99c25051732eab4851569851a7b..8022694f704a40f9d220c23c2b5fe93cc43d874b 100644 (file)
@@ -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);
index e7cfeab6d00c003e6db641f3f712a61c5ed095f9..68b9cbe606232ab2cc55ffd5e6ef0d6bdfb7df19 100644 (file)
@@ -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");
 }