about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMartin Nordholts <martin.nordholts@codetale.se>2024-02-24 11:19:14 +0100
committerMartin Nordholts <martin.nordholts@codetale.se>2024-02-24 16:18:34 +0100
commitf5b9eaf18f3486feaf6bf765409449e37b38f9d2 (patch)
treef2147ae5589ab0ca836bc225cc846c3bfd456151
parent21033f637e60af61ead04cc296e7214f89c16a95 (diff)
downloadrust-f5b9eaf18f3486feaf6bf765409449e37b38f9d2.tar.gz
rust-f5b9eaf18f3486feaf6bf765409449e37b38f9d2.zip
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.
-rw-r--r--tests/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs12
1 files 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 74fbae0350e..3d93d50ca3f 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");
     }
 }