From 6c759e57cc80b57313a2a4bec2a4ae79d847b5c5 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Mon, 10 Oct 2022 20:28:11 +0000 Subject: [PATCH] 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. --- crates/oyster_runtime/src/pipeline.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/crates/oyster_runtime/src/pipeline.rs b/crates/oyster_runtime/src/pipeline.rs index f2ec863..5ee036b 100644 --- a/crates/oyster_runtime/src/pipeline.rs +++ b/crates/oyster_runtime/src/pipeline.rs @@ -65,23 +65,16 @@ impl<'a> PreparedCommand<'a> { cmd.stderr(self.stderr.map_or(Stdio::inherit(), Stdio::from)); cmd.process_group(pgid.as_raw()); - { - let pgid = *pgid; - unsafe { - cmd.pre_exec(move || { - if pgid == Pid::from_raw(0) { - let _ = unistd::tcsetpgrp(libc::STDIN_FILENO, unistd::getpid()); - } + unsafe { + cmd.pre_exec(move || { + let _ = unistd::tcsetpgrp(libc::STDIN_FILENO, unistd::getpid()); - let default = - SigAction::new(SigHandler::SigDfl, SaFlags::empty(), SigSet::empty()); + let default = 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); - let _ = signal::sigaction(signal::Signal::SIGTTOU, &default); - - Ok(()) - }); - } + Ok(()) + }); } let child = match cmd.spawn() {