From fe3d05d36b8776c8102926d91c6d24fbc9ad4dc1 Mon Sep 17 00:00:00 2001 From: Charlotte Meyer Date: Sun, 25 Sep 2022 12:17:55 +0000 Subject: [PATCH] fix(runtime): reset signal handlers in children Ignored signals do not get reset on exec. This allows children to properly suspend when needed. --- crates/oyster_runtime/src/pipeline.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/oyster_runtime/src/pipeline.rs b/crates/oyster_runtime/src/pipeline.rs index 8bc5e0f..ae4a62c 100644 --- a/crates/oyster_runtime/src/pipeline.rs +++ b/crates/oyster_runtime/src/pipeline.rs @@ -13,7 +13,8 @@ use nix::{ fcntl::OFlag, libc, sys::{ - signal, + signal::{self, SaFlags, SigAction, SigHandler}, + signalfd::SigSet, wait::{self, WaitPidFlag, WaitStatus}, }, unistd::{self, Pid}, @@ -47,10 +48,20 @@ impl<'a> PreparedCommand<'a> { cmd.stderr(self.stderr.map_or(Stdio::inherit(), Stdio::from)); cmd.process_group(pgid.as_raw()); - if *pgid == Pid::from_raw(0) { + { + let pgid = *pgid; unsafe { cmd.pre_exec(move || { - let _ = unistd::tcsetpgrp(libc::STDIN_FILENO, unistd::getpid()); + if pgid == Pid::from_raw(0) { + let _ = unistd::tcsetpgrp(libc::STDIN_FILENO, unistd::getpid()); + } + + let default = + SigAction::new(SigHandler::SigDfl, SaFlags::empty(), SigSet::empty()); + + let _ = signal::sigaction(signal::Signal::SIGTSTP, &default); + let _ = signal::sigaction(signal::Signal::SIGTTOU, &default); + Ok(()) }); }