From b693db16cc595ae7dba2bc52d1576fa80e58a110 Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Sat, 15 Jul 2023 15:30:29 +1200 Subject: [PATCH] Revert "Fix SIGTTIN handling" (#9694) Reverts nushell/nushell#9681 As mentioned in #9681 - this breaks running tests in wsl2. --- src/terminal.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/terminal.rs b/src/terminal.rs index f8d3c777e8..6d20299fbb 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -59,11 +59,12 @@ fn take_control(interactive: bool) { } } + let mut success = false; for _ in 0..4096 { match unistd::tcgetpgrp(nix::libc::STDIN_FILENO) { Ok(owner_pgid) if owner_pgid == shell_pgid => { - // success - return; + success = true; + break; } Ok(owner_pgid) if owner_pgid == Pid::from_raw(0) => { // Zero basically means something like "not owned" and we can just take it @@ -79,7 +80,7 @@ fn take_control(interactive: bool) { } _ => { // fish also has other heuristics than "too many attempts" for the orphan check, but they're optional - if signal::killpg(shell_pgid, Signal::SIGTTIN).is_err() { + if signal::killpg(Pid::from_raw(-shell_pgid.as_raw()), Signal::SIGTTIN).is_err() { if !interactive { // that's fine return; @@ -90,8 +91,7 @@ fn take_control(interactive: bool) { } } } - - if interactive { + if !success && interactive { eprintln!("ERROR: failed take control of the terminal, we might be orphaned"); std::process::exit(1); }