|
| 1 | +//@ revisions: default sig_dfl sig_ign inherit |
| 2 | +//@ aux-build:assert-sigpipe-disposition-bin.rs |
| 3 | +//@ aux-build:sigpipe-utils.rs |
| 4 | +//@ ignore-cross-compile because we run the compiled code |
| 5 | +//@ only-unix because SIGPIPE is a unix thing |
| 6 | +//@ run-pass |
| 7 | + |
| 8 | +// Checks the signal disposition of `SIGPIPE` in child processes, and in our own |
| 9 | +// process for robustness. Without any `unix_sigpipe` attribute, `SIG_IGN` is |
| 10 | +// the default. But there is a difference in how `SIGPIPE` is treated in child |
| 11 | +// processes with and without the attribute. Search for |
| 12 | +// `unix_sigpipe_attr_specified()` in the code base to learn more. |
| 13 | + |
| 14 | +#![feature(rustc_private)] |
| 15 | +#![cfg_attr(any(sig_dfl, sig_ign, inherit), feature(unix_sigpipe))] |
| 16 | + |
| 17 | +extern crate libc; |
| 18 | + |
| 19 | +// We need `aux-build` for `assert-sigpipe-disposition-bin`, and `compiletest` |
| 20 | +// gets confused if we use both `aux-build` and `aux-crate` in the same test, so |
| 21 | +// we need to use the old style of bringing `sigpipe_utils` in scope. |
| 22 | +extern crate sigpipe_utils; |
| 23 | + |
| 24 | +use sigpipe_utils::*; |
| 25 | + |
| 26 | +#[cfg_attr(sig_dfl, unix_sigpipe = "sig_dfl")] |
| 27 | +#[cfg_attr(sig_ign, unix_sigpipe = "sig_ign")] |
| 28 | +#[cfg_attr(inherit, unix_sigpipe = "inherit")] |
| 29 | +fn main() { |
| 30 | + // By default, we get SIG_IGN but the child gets SIG_DFL. |
| 31 | + #[cfg(default)] |
| 32 | + let (we_expect, child_expects) = (SignalHandler::Ignore, "SIG_DFL"); |
| 33 | + |
| 34 | + // With #[unix_sigpipe = "sig_dfl"] we get SIG_DFL and the child does too. |
| 35 | + #[cfg(sig_dfl)] |
| 36 | + let (we_expect, child_expects) = (SignalHandler::Default, "SIG_DFL"); |
| 37 | + |
| 38 | + // With #[unix_sigpipe = "sig_ign"] we get SIG_IGN and the child does too. |
| 39 | + #[cfg(sig_ign)] |
| 40 | + let (we_expect, child_expects) = (SignalHandler::Ignore, "SIG_IGN"); |
| 41 | + |
| 42 | + // With #[unix_sigpipe = "inherit"] we get SIG_DFL and the child does too. |
| 43 | + #[cfg(inherit)] |
| 44 | + let (we_expect, child_expects) = (SignalHandler::Default, "SIG_DFL"); |
| 45 | + |
| 46 | + assert_sigpipe_handler(we_expect); |
| 47 | + |
| 48 | + assert!( |
| 49 | + std::process::Command::new("./auxiliary/assert-sigpipe-disposition-bin") |
| 50 | + .arg(child_expects) |
| 51 | + .status() |
| 52 | + .unwrap() |
| 53 | + .success() |
| 54 | + ); |
| 55 | +} |
0 commit comments