Skip to content

Commit f5b9eaf

Browse files
committedFeb 24, 2024
Don't unnecessarily change SIGPIPE disposition in unix_sigpipe tests
In `auxiliary/sigpipe-utils.rs`, all we want to know is the current `SIGPIPE` disposition. We should not change it. So use `libc::sigaction` instead of `libc::signal`. That way we can also remove the code that restores it.
1 parent 21033f6 commit f5b9eaf

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed
 

‎tests/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ pub fn assert_sigpipe_handler(expected_handler: SignalHandler) {
1717
target_os = "android",
1818
)))]
1919
{
20-
let prev = unsafe { libc::signal(libc::SIGPIPE, libc::SIG_IGN) };
20+
let actual = unsafe {
21+
let mut actual: libc::sigaction = std::mem::zeroed();
22+
libc::sigaction(libc::SIGPIPE, std::ptr::null(), &mut actual);
23+
actual.sa_sigaction
24+
};
2125

2226
let expected = match expected_handler {
2327
SignalHandler::Ignore => libc::SIG_IGN,
2428
SignalHandler::Default => libc::SIG_DFL,
2529
};
26-
assert_eq!(prev, expected, "expected sigpipe value matches actual value");
2730

28-
// Unlikely to matter, but restore the old value anyway
29-
unsafe {
30-
libc::signal(libc::SIGPIPE, prev);
31-
};
31+
assert_eq!(actual, expected, "actual and expected SIGPIPE disposition differs");
3232
}
3333
}

0 commit comments

Comments
 (0)
Please sign in to comment.