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.
This commit is contained in:
+2
-2
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user