Add a way to set the signal mask of a child process

Currently, when Rust spawns a process on Unix, it always sets the signal mask to the empty set.

It would be great if there were a way to configure this. My own use case is to block SIGTSTP and other signals, to work around a flaw in the definition of posix_spawn. This is currently not possible to do with the Rust std::process::Command APIs.

The general outline of the API I'd propose would be a new method on CommandExt:

pub fn signal_mask(&mut self, mask: SignalMask) -> &mut Command;

pub struct SignalMask {
    // impl as maybe a sigset_t
}

impl SignalMask {
    pub fn empty() -> Self;
    pub fn filled() -> Self;
    pub fn add_signal(&mut self, signal: i32) -> &mut Self;
    pub fn remove_signal(&mut self, signal: i32) -> &mut Self;
}
5 Likes

I wrote up a simple draft PR with my proposed API: [WIP] implement signal mask support by sunshowers · Pull Request #100737 · rust-lang/rust · GitHub

It's pretty straightforward I think!

5 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.