From 041a26f6471e58ce3213f5cd93aceffd8120ac7e Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Thu, 4 Jul 2024 22:19:48 +0800 Subject: [PATCH] Update TTY modes for external commands only after successful command According to the discussion in #2315, we adopt TTY modes for external commands mainly for "stty". If our child process crashes (or SSH disconnect), we might get weird modes. Let's ignore the modes in the failure case. Co-authored-by: Johannes Altmanninger Part of #10603 --- CHANGELOG.rst | 1 + src/reader.rs | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 19798c405..84bd499cb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -155,6 +155,7 @@ Interactive improvements - ``read --help`` and friends no longer ignore redirections. This fixes a regression in version 3.1 (:issue:`10274`). - Measuring a command with ``time`` now considers the time taken for command substitution (:issue:`9100`). - ``fish_add_path`` now automatically enables verbose mode when used interactively (in the commandline), in an effort to be clearer about what it does (:issue:`10532`). +- fish no longer adopts TTY modes of failed commands (:issue:`10603`). New or improved bindings ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/reader.rs b/src/reader.rs index 36c87bfbb..7046f63c3 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -3680,8 +3680,10 @@ pub fn term_copy_modes() { } /// Grab control of terminal. -fn term_steal() { - term_copy_modes(); +fn term_steal(copy_modes: bool) { + if copy_modes { + term_copy_modes(); + } while unsafe { libc::tcsetattr(STDIN_FILENO, TCSANOW, &*shell_modes()) } == -1 { if errno().0 == EIO { redirect_tty_output(); @@ -4986,7 +4988,7 @@ fn reader_run_command(parser: &Parser, cmd: &wstr) -> EvalRes { ); } - term_steal(); + term_steal(eval_res.status.is_success()); // Provide value for `status current-command` parser.libdata_mut().status_vars.command = (*PROGRAM_NAME.get().unwrap()).to_owned();