|
| 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-sigpipe-disposition.rs |
1 | 4 | //@ run-pass
|
2 |
| -//@ aux-build:sigpipe-utils.rs |
3 | 5 |
|
4 |
| -#![feature(unix_sigpipe)] |
| 6 | +#![feature(rustc_private, unix_sigpipe)] |
5 | 7 |
|
6 |
| -#[unix_sigpipe = "inherit"] |
| 8 | +extern crate libc; |
| 9 | + |
| 10 | +// By default the Rust runtime resets SIGPIPE to SIG_DFL before exec:ing child |
| 11 | +// processes so opt-out of that with `#[unix_sigpipe = "sig_dfl"]`. See |
| 12 | +// https://github.com/rust-lang/rust/blob/bf4de3a874753bbee3323081c8b0c133444fed2d/library/std/src/sys/pal/unix/process/process_unix.rs#L359-L384 |
| 13 | +#[unix_sigpipe = "sig_dfl"] |
7 | 14 | fn main() {
|
8 |
| - extern crate sigpipe_utils; |
| 15 | + // First expect SIG_DFL in a child process with #[unix_sigpipe = "inherit"]. |
| 16 | + assert_inherit_sigpipe_disposition("SIG_DFL"); |
| 17 | + |
| 18 | + // With SIGPIPE as SIG_IGN the same program shall get SIG_IGN instead. |
| 19 | + unsafe { |
| 20 | + libc::signal(libc::SIGPIPE, libc::SIG_IGN); |
| 21 | + } |
| 22 | + assert_inherit_sigpipe_disposition("SIG_IGN"); |
| 23 | +} |
9 | 24 |
|
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); |
| 25 | +fn assert_inherit_sigpipe_disposition(expected: &str) { |
| 26 | + let mut cmd = std::process::Command::new("auxiliary/bin/assert-inherit-sigpipe-disposition"); |
| 27 | + cmd.arg(expected); |
| 28 | + assert!(cmd.status().unwrap().success()); |
14 | 29 | }
|
0 commit comments