Skip to main content

process_wrap/tokio/
reset_sigmask.rs

1use std::io::Result;
2
3use nix::sys::signal::{SigSet, SigmaskHow, sigprocmask};
4use tokio::process::Command;
5
6use super::{CommandWrap, CommandWrapper};
7
8/// Wrapper which resets the process signal mask.
9///
10/// By default a Command on Unix inherits its parent's [signal mask]. However, in some cases this
11/// is not what you want. This wrapper resets the command's sigmask by unblocking all signals.
12#[derive(Clone, Copy, Debug)]
13pub struct ResetSigmask;
14
15impl CommandWrapper for ResetSigmask {
16	fn pre_spawn(&mut self, command: &mut Command, _core: &CommandWrap) -> Result<()> {
17		unsafe {
18			command.pre_exec(|| {
19				let newset = SigSet::all();
20				sigprocmask(SigmaskHow::SIG_UNBLOCK, Some(&newset), None)?;
21				Ok(())
22			});
23		}
24		Ok(())
25	}
26}