Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix SIGTTIN handling" #9694

Merged
merged 1 commit into from
Jul 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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);
}
Expand Down