Skip to main content

process_wrap/std/
reset_sigmask.rs

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