-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to set the signal mask of a child process #88
Comments
I wrote a concern about the safety of this here rust-lang/rust#100737 (comment). I don't think its a big issue, but I do want to make a note of it here. It's definitely something we should be sure about prior to whenever we stabilize this, but I can't see a way for it to be unsound at the moment (but I have not thought about this for very long), so I don't have any objections to it being safe. |
Because it's not written out here, the API surface being proposed in the PR is: // Inside `std::os::unix::process`
pub trait CommandExt: Sealed {
// <...snip: existing methods here...>
fn signal_mask(&mut self, mask: impl Into<Option<SignalSet>>) -> &mut std::process::Command;
}
pub struct SignalSet { .. }
impl SignalSet {
pub fn empty() -> std::io::Result<Self>;
pub fn filled() -> std::io::Result<Self>;
pub fn insert(&mut self, signal: i32) -> std::io::Result<&mut Self>;
pub fn remove(&mut self, signal: i32) -> std::io::Result<&mut Self>;
pub fn contains(&self, signal: i32) -> std::io::Result<bool>;
} I think |
I've updated the API based on a suggestion by @zackw. |
|
We discussed this in today's meeting. We're ok with adding signalmasking for the child process but the proposed API needs some polish.
We are in favor of deferring until spawn.
We haven't reached a decision on that and it should be listed as open question in the tracking issue. |
This is only mostly true, and the exceptions matter. In the C world, if you don't do anything special, child processes start out with a copy of the parent's signal mask, whatever it is. There are shell utilities (e.g. But this means that a program may start out with some signals masked, and that it might have a positive reason to unmask some of those signals for child processes, and therefore [note: nohup from coreutils 8.32, which is the only implementation I can conveniently test right now, actually works by setting the signal disposition for SIGHUP, but I'm pretty sure there do, or did, exist implementations that worked by manipulating the signal mask.] |
Proposal
Currently, when Rust spawns a process on Unix, it always sets the signal mask to the empty set.
posix_spawn
: https://github.com/rust-lang/rust/blob/7fe2c4b00dfbc33643e1af4b293eb057306a8339/library/std/src/sys/unix/process/process_unix.rs#L532-L539fork
/exec
: https://github.com/rust-lang/rust/blob/7fe2c4b00dfbc33643e1af4b293eb057306a8339/library/std/src/sys/unix/process/process_unix.rs#L340This 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 Ruststd::process::Command
APIs.Solution sketches
Proposed API, using the suggestion by @zackw in this comment:
I put up a PR with this API:
Questions:
io::Error
s returned by these methods be deferred untilspawn()
? I think doing it immediately is better to indicate errors (for invalid signals) immediately.CommandExt::signal_mask
be marked unsafe? See discussion here.Future directions:
setsigdefault
as well. Currently we always setSIGPIPE
.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.
The text was updated successfully, but these errors were encountered: