diff options
| author | Rain <rain@sunshowers.io> | 2022-09-22 22:48:14 -0700 |
|---|---|---|
| committer | Rain <rain@sunshowers.io> | 2022-10-20 14:53:38 -0700 |
| commit | a52c79e859142c1cd5c0c5bdb73f16b754e1b98f (patch) | |
| tree | ac8aea871f084c1521a9ee86c6adc3cf19313967 /src | |
| parent | 542febd2d383b5082277c7d165b098c0a3b513f6 (diff) | |
| download | rust-a52c79e859142c1cd5c0c5bdb73f16b754e1b98f.tar.gz rust-a52c79e859142c1cd5c0c5bdb73f16b754e1b98f.zip | |
Change process spawning to inherit the parent's signal mask by default
Previously, the signal mask is always reset when a child process is started. This breaks tools like `nohup` which expect `SIGHUP` to be blocked. With this change, the default behavior changes to inherit the signal mask. This also changes the signal disposition for `SIGPIPE` to only be changed if the `#[unix_sigpipe]` attribute isn't set.
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc/unstable-book/src/language-features/unix-sigpipe.md | 10 | ||||
| -rw-r--r-- | src/test/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs | 6 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/doc/unstable-book/src/language-features/unix-sigpipe.md b/src/doc/unstable-book/src/language-features/unix-sigpipe.md index aa39b6eb288..7ed6a7de895 100644 --- a/src/doc/unstable-book/src/language-features/unix-sigpipe.md +++ b/src/doc/unstable-book/src/language-features/unix-sigpipe.md @@ -36,7 +36,7 @@ hello world Set the `SIGPIPE` handler to `SIG_IGN` before invoking `fn main()`. This will result in `ErrorKind::BrokenPipe` errors if you program tries to write to a closed pipe. This is normally what you want if you for example write socket servers, socket clients, or pipe peers. -This is what libstd has done by default since 2014. Omitting `#[unix_sigpipe = "..."]` is the same as having `#[unix_sigpipe = "sig_ign"]`. +This is what libstd has done by default since 2014. (However, see the note on child processes below.) ### Example @@ -52,3 +52,11 @@ hello world thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', library/std/src/io/stdio.rs:1016:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` + +### Note on child processes + +When spawning child processes, the legacy Rust behavior if `#[unix_sigpipe]` is not specified is to +reset `SIGPIPE` to `SIG_DFL`. + +If `#[unix_sigpipe = "..."]` is specified, no matter what its value is, the signal disposition of +`SIGPIPE` is no longer reset. This means that the child inherits the parent's `SIGPIPE` behavior. diff --git a/src/test/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs b/src/test/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs index e8b4fe7ae52..74fbae0350e 100644 --- a/src/test/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs +++ b/src/test/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs @@ -23,9 +23,11 @@ pub fn assert_sigpipe_handler(expected_handler: SignalHandler) { SignalHandler::Ignore => libc::SIG_IGN, SignalHandler::Default => libc::SIG_DFL, }; - assert_eq!(prev, expected); + assert_eq!(prev, expected, "expected sigpipe value matches actual value"); // Unlikely to matter, but restore the old value anyway - unsafe { libc::signal(libc::SIGPIPE, prev); }; + unsafe { + libc::signal(libc::SIGPIPE, prev); + }; } } |
