|
| 1 | +//@ ignore-cross-compile because aux-bin does not yet support it |
| 2 | +//@ only-unix because SIGPIPE is a unix thing |
| 3 | +//@ aux-bin: assert-inherit-sig_dfl.rs |
| 4 | +//@ aux-bin: assert-inherit-sig_ign.rs |
1 | 5 | //@ run-pass
|
2 |
| -//@ aux-build:sigpipe-utils.rs |
3 | 6 |
|
4 |
| -#![feature(unix_sigpipe)] |
| 7 | +#![feature(rustc_private, unix_sigpipe)] |
5 | 8 |
|
6 |
| -#[unix_sigpipe = "inherit"] |
| 9 | +extern crate libc; |
| 10 | + |
| 11 | +// By default the Rust runtime resets SIGPIPE to SIG_DFL before exec:ing child |
| 12 | +// processes so opt-out of that with `#[unix_sigpipe = "sig_dfl"]`. See |
| 13 | +// https://github.com/rust-lang/rust/blob/bf4de3a874753bbee3323081c8b0c133444fed2d/library/std/src/sys/pal/unix/process/process_unix.rs#L359-L384 |
| 14 | +#[unix_sigpipe = "sig_dfl"] |
7 | 15 | fn main() {
|
8 |
| - extern crate sigpipe_utils; |
| 16 | + // First expect SIG_DFL in a child process with #[unix_sigpipe = "inherit"]. |
| 17 | + assert_inherit_sigpipe_disposition("auxiliary/bin/assert-inherit-sig_dfl"); |
| 18 | + |
| 19 | + // With SIG_IGN we expect #[unix_sigpipe = "inherit"] to also get SIG_IGN. |
| 20 | + unsafe { |
| 21 | + libc::signal(libc::SIGPIPE, libc::SIG_IGN); |
| 22 | + } |
| 23 | + assert_inherit_sigpipe_disposition("auxiliary/bin/assert-inherit-sig_ign"); |
| 24 | +} |
9 | 25 |
|
10 |
| - // #[unix_sigpipe = "inherit"] is active, so SIGPIPE shall NOT be ignored, |
11 |
| - // instead the default handler shall be installed. (We assume that the |
12 |
| - // process that runs these tests have the default handler.) |
13 |
| - sigpipe_utils::assert_sigpipe_handler(sigpipe_utils::SignalHandler::Default); |
| 26 | +fn assert_inherit_sigpipe_disposition(aux_bin: &str) { |
| 27 | + let mut cmd = std::process::Command::new(aux_bin); |
| 28 | + assert!(cmd.status().unwrap().success()); |
14 | 29 | }
|
0 commit comments