Skip to content

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

Closed
@sunshowers

Description

@sunshowers

Proposal

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

This proposal adds a way to set the signal mask for a process.

Motivation, use-cases

There are a variety of use cases for signal masks, but 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.

Solution sketches

Proposed API, using the suggestion by @zackw in this comment:

pub trait CommandExt: Sealed {
    // <...snip: existing methods here...>

    fn block_signal(&mut self, signal: i32) -> io::Result<&mut std::process::Command>;
    fn unblock_signal(&mut self, signal: i32) -> io::Result<&mut std::process::Command>;
    fn will_block_signal(&self, signal: i32) -> io::Result<&mut std::process::Command>;
}

I put up a PR with this API:

Questions:

  • Should the io::Errors returned by these methods be deferred until spawn()? I think doing it immediately is better to indicate errors (for invalid signals) immediately.
  • Should CommandExt::signal_mask be marked unsafe? See discussion here.

Future directions:

  • This can be extended to support setsigdefault as well. Currently we always set SIGPIPE.

Links and related work

Post in the internals group: https://internals.rust-lang.org/t/add-a-way-to-set-the-signal-mask-of-a-child-process/17220

What happens now?

This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions