diff --git a/tokio/src/process/unix/mod.rs b/tokio/src/process/unix/mod.rs index c9d1035f53d..832416067c6 100644 --- a/tokio/src/process/unix/mod.rs +++ b/tokio/src/process/unix/mod.rs @@ -116,6 +116,14 @@ impl fmt::Debug for Child { } pub(crate) fn spawn_child(cmd: &mut std::process::Command) -> io::Result { + // block SIGCHLD to avoid race condition with spawn and signal handler registration + unsafe { + let mut mask: libc::sigset_t = std::mem::zeroed(); + libc::sigemptyset(&mut mask); + libc::sigaddset(&mut mask, libc::SIGCHLD); + libc::sigprocmask(libc::SIG_BLOCK, &mask, std::ptr::null_mut()); + } + let mut child = cmd.spawn()?; let stdin = child.stdin.take().map(stdio).transpose()?; let stdout = child.stdout.take().map(stdio).transpose()?; @@ -137,6 +145,14 @@ pub(crate) fn spawn_child(cmd: &mut std::process::Command) -> io::Result