Skip to content

Commit 0e58cbd

Browse files
committed
Test #[unix_sigpipe = "inherit"] with both SIG_DFL and SIG_IGN
Add a test that fails if `#[unix_sigpipe = "inherit"]` wrongly results in `SIGPIPE` being `SIG_DFL` if the parent has `SIG_IGN`. We have no current test for this particular case.
1 parent defef86 commit 0e58cbd

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![feature(unix_sigpipe, rustc_private)]
2+
3+
extern crate libc;
4+
5+
#[unix_sigpipe = "inherit"]
6+
fn main() {
7+
let arg1 = std::env::args()
8+
.skip(1)
9+
.next()
10+
.expect("Must pass SIG_IGN or SIG_DFL as first arg");
11+
12+
let expected = match arg1.as_str() {
13+
"SIG_IGN" => libc::SIG_IGN,
14+
"SIG_DFL" => libc::SIG_DFL,
15+
arg => panic!("Must pass SIG_IGN or SIG_DFL as first arg. Got: {}", arg),
16+
};
17+
18+
let actual = unsafe {
19+
let mut actual: libc::sigaction = std::mem::zeroed();
20+
libc::sigaction(libc::SIGPIPE, std::ptr::null(), &mut actual);
21+
actual.sa_sigaction
22+
};
23+
24+
assert_eq!(
25+
actual, expected,
26+
"actual and expected SIGPIPE disposition in differs"
27+
);
28+
}
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-sigpipe-disposition.rs
14
//@ run-pass
2-
//@ aux-build:sigpipe-utils.rs
35

4-
#![feature(unix_sigpipe)]
6+
#![feature(rustc_private, unix_sigpipe)]
57

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"]
714
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+
}
924

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

0 commit comments

Comments
 (0)