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 <aclopte@gmail.com>

Part of #10603
This commit is contained in:
Amos Bird 2024-07-04 22:19:48 +08:00 committed by Johannes Altmanninger
parent 56a4ae17c9
commit 041a26f647
2 changed files with 6 additions and 3 deletions

View File

@ -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
^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -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();