1 #![feature(rustc_private)]
2 extern crate libc;
3
4 /// So tests don't have to bring libc in scope themselves
5 pub enum SignalHandler {
6 Ignore,
7 Default,
8 }
9
10 /// Helper to assert that [`libc::SIGPIPE`] has the expected signal handler.
assert_sigpipe_handler(expected_handler: SignalHandler)11 pub fn assert_sigpipe_handler(expected_handler: SignalHandler) {
12 #[cfg(unix)]
13 #[cfg(not(any(
14 target_os = "emscripten",
15 target_os = "fuchsia",
16 target_os = "horizon",
17 target_os = "android",
18 )))]
19 {
20 let prev = unsafe { libc::signal(libc::SIGPIPE, libc::SIG_IGN) };
21
22 let expected = match expected_handler {
23 SignalHandler::Ignore => libc::SIG_IGN,
24 SignalHandler::Default => libc::SIG_DFL,
25 };
26 assert_eq!(prev, expected, "expected sigpipe value matches actual value");
27
28 // Unlikely to matter, but restore the old value anyway
29 unsafe {
30 libc::signal(libc::SIGPIPE, prev);
31 };
32 }
33 }
34