2022-07-05 12:56:22 -05:00
|
|
|
#![feature(rustc_private)]
|
|
|
|
extern crate libc;
|
|
|
|
|
|
|
|
/// So tests don't have to bring libc in scope themselves
|
|
|
|
pub enum SignalHandler {
|
|
|
|
Ignore,
|
|
|
|
Default,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Helper to assert that [`libc::SIGPIPE`] has the expected signal handler.
|
|
|
|
pub fn assert_sigpipe_handler(expected_handler: SignalHandler) {
|
|
|
|
#[cfg(unix)]
|
2022-08-29 13:39:23 -05:00
|
|
|
#[cfg(not(any(
|
|
|
|
target_os = "emscripten",
|
|
|
|
target_os = "fuchsia",
|
|
|
|
target_os = "horizon",
|
|
|
|
target_os = "android",
|
|
|
|
)))]
|
2022-07-05 12:56:22 -05:00
|
|
|
{
|
|
|
|
let prev = unsafe { libc::signal(libc::SIGPIPE, libc::SIG_IGN) };
|
|
|
|
|
|
|
|
let expected = match expected_handler {
|
|
|
|
SignalHandler::Ignore => libc::SIG_IGN,
|
|
|
|
SignalHandler::Default => libc::SIG_DFL,
|
|
|
|
};
|
2022-09-23 00:48:14 -05:00
|
|
|
assert_eq!(prev, expected, "expected sigpipe value matches actual value");
|
2022-07-05 12:56:22 -05:00
|
|
|
|
|
|
|
// Unlikely to matter, but restore the old value anyway
|
2022-09-23 00:48:14 -05:00
|
|
|
unsafe {
|
|
|
|
libc::signal(libc::SIGPIPE, prev);
|
|
|
|
};
|
2022-07-05 12:56:22 -05:00
|
|
|
}
|
|
|
|
}
|