From f5b9eaf18f3486feaf6bf765409449e37b38f9d2 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Sat, 24 Feb 2024 11:19:14 +0100 Subject: [PATCH] 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. --- .../unix_sigpipe/auxiliary/sigpipe-utils.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs b/tests/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs index 74fbae0350e48..3d93d50ca3fbb 100644 --- a/tests/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs +++ b/tests/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs @@ -17,17 +17,17 @@ pub fn assert_sigpipe_handler(expected_handler: SignalHandler) { target_os = "android", )))] { - let prev = unsafe { libc::signal(libc::SIGPIPE, libc::SIG_IGN) }; + let actual = unsafe { + let mut actual: libc::sigaction = std::mem::zeroed(); + libc::sigaction(libc::SIGPIPE, std::ptr::null(), &mut actual); + actual.sa_sigaction + }; let expected = match expected_handler { SignalHandler::Ignore => libc::SIG_IGN, SignalHandler::Default => libc::SIG_DFL, }; - assert_eq!(prev, expected, "expected sigpipe value matches actual value"); - // Unlikely to matter, but restore the old value anyway - unsafe { - libc::signal(libc::SIGPIPE, prev); - }; + assert_eq!(actual, expected, "actual and expected SIGPIPE disposition differs"); } }