Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't unnecessarily change SIGPIPE disposition in unix_sigpipe tests #121554

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tests/ui/attributes/unix_sigpipe/auxiliary/sigpipe-utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sad that libc doesn't have a good way to init this, can't even do it fully safely manually, because some fields have private fields :(

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");
}
}
Loading