fix(runtime): set fg pgrp in all children

Before there was a race condition, where it relied on the scheduler
running the first child first.
This commit is contained in:
buffet 2022-10-10 20:28:11 +00:00
parent f0e15804b4
commit 6c759e57cc

View file

@ -65,23 +65,16 @@ impl<'a> PreparedCommand<'a> {
cmd.stderr(self.stderr.map_or(Stdio::inherit(), Stdio::from)); cmd.stderr(self.stderr.map_or(Stdio::inherit(), Stdio::from));
cmd.process_group(pgid.as_raw()); cmd.process_group(pgid.as_raw());
{ unsafe {
let pgid = *pgid; cmd.pre_exec(move || {
unsafe { let _ = unistd::tcsetpgrp(libc::STDIN_FILENO, unistd::getpid());
cmd.pre_exec(move || {
if pgid == Pid::from_raw(0) {
let _ = unistd::tcsetpgrp(libc::STDIN_FILENO, unistd::getpid());
}
let default = let default = SigAction::new(SigHandler::SigDfl, SaFlags::empty(), SigSet::empty());
SigAction::new(SigHandler::SigDfl, SaFlags::empty(), SigSet::empty()); let _ = signal::sigaction(signal::Signal::SIGTSTP, &default);
let _ = signal::sigaction(signal::Signal::SIGTTOU, &default);
let _ = signal::sigaction(signal::Signal::SIGTSTP, &default); Ok(())
let _ = signal::sigaction(signal::Signal::SIGTTOU, &default); });
Ok(())
});
}
} }
let child = match cmd.spawn() { let child = match cmd.spawn() {