mirror of
https://github.com/nushell/nushell
synced 2025-01-27 20:35:43 +00:00
Fix SIGTTIN handling (#9681)
# Description
Due to a typo? in the
[reference](https://www.gnu.org/software/libc/manual/html_node/Initializing-the-Shell.html)
used to implement SIGTTIN handling, nushell will crash when being sent
to the background from within another shell.
For example, currently in bash:
```bash
$ nu -n &
[1] 176058
$ ERROR: failed to SIGTTIN ourselves
[1]+ Exit 1 nu -n
$
```
Now fixed:
```bash
$ nu -n &
[1] 178788
$ jobs
[1]+ Stopped nu -n
$
```
For further reference, this is how
[fish](493cbeb84c/src/reader.cpp (L2571)
)
does it.
# User-Facing Changes
Bug fix only -- users should now be able to send nushell to the
background.
This commit is contained in:
parent
4804e6a151
commit
2fc9506bc7
1 changed files with 5 additions and 5 deletions
|
@ -59,12 +59,11 @@ fn take_control(interactive: bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut success = false;
|
|
||||||
for _ in 0..4096 {
|
for _ in 0..4096 {
|
||||||
match unistd::tcgetpgrp(nix::libc::STDIN_FILENO) {
|
match unistd::tcgetpgrp(nix::libc::STDIN_FILENO) {
|
||||||
Ok(owner_pgid) if owner_pgid == shell_pgid => {
|
Ok(owner_pgid) if owner_pgid == shell_pgid => {
|
||||||
success = true;
|
// success
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
Ok(owner_pgid) if owner_pgid == Pid::from_raw(0) => {
|
Ok(owner_pgid) if owner_pgid == Pid::from_raw(0) => {
|
||||||
// Zero basically means something like "not owned" and we can just take it
|
// Zero basically means something like "not owned" and we can just take it
|
||||||
|
@ -80,7 +79,7 @@ fn take_control(interactive: bool) {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// fish also has other heuristics than "too many attempts" for the orphan check, but they're optional
|
// fish also has other heuristics than "too many attempts" for the orphan check, but they're optional
|
||||||
if signal::killpg(Pid::from_raw(-shell_pgid.as_raw()), Signal::SIGTTIN).is_err() {
|
if signal::killpg(shell_pgid, Signal::SIGTTIN).is_err() {
|
||||||
if !interactive {
|
if !interactive {
|
||||||
// that's fine
|
// that's fine
|
||||||
return;
|
return;
|
||||||
|
@ -91,7 +90,8 @@ fn take_control(interactive: bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !success && interactive {
|
|
||||||
|
if interactive {
|
||||||
eprintln!("ERROR: failed take control of the terminal, we might be orphaned");
|
eprintln!("ERROR: failed take control of the terminal, we might be orphaned");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue