Skip to content

Commit 7b5165c

Browse files
authored
Rollup merge of rust-lang#123316 - Enselic:sigpipe-inherit-variants, r=fmease
Test `#[unix_sigpipe = "inherit"]` with both `SIG_DFL` and `SIG_IGN` Extend our `#[unix_sigpipe = "inherit"]` test so that it detects if `SIGPIPE` wrongly ends up being `SIG_DFL` when the parent has `SIG_IGN`. We have no current test for this particular case. Tracking issue: rust-lang#97889
2 parents 52405aa + 4559e61 commit 7b5165c

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ aux-crate: sigpipe_utils=sigpipe-utils.rs
2+
3+
#![feature(unix_sigpipe)]
4+
5+
#[unix_sigpipe = "inherit"]
6+
fn main() {
7+
sigpipe_utils::assert_sigpipe_handler(sigpipe_utils::SignalHandler::Default);
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ aux-crate: sigpipe_utils=sigpipe-utils.rs
2+
3+
#![feature(unix_sigpipe)]
4+
5+
#[unix_sigpipe = "inherit"]
6+
fn main() {
7+
sigpipe_utils::assert_sigpipe_handler(sigpipe_utils::SignalHandler::Ignore);
8+
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
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
15
//@ run-pass
2-
//@ aux-build:sigpipe-utils.rs
36

4-
#![feature(unix_sigpipe)]
7+
#![feature(rustc_private, unix_sigpipe)]
58

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"]
715
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+
}
925

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());
1429
}

0 commit comments

Comments
 (0)