Skip to content

Commit 5dc385f

Browse files
committed
Simplify target_os checks
1 parent 70b3ada commit 5dc385f

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

signal-hook-registry/src/lib.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,9 @@ impl Slot {
159159
// C data structure, expected to be zeroed out.
160160
let mut new: libc::sigaction = unsafe { mem::zeroed() };
161161
#[cfg(not(target_os = "aix"))]
162-
let set_handler =
163-
|action: &mut libc::sigaction, handler| action.sa_sigaction = handler as usize;
162+
{ new.sa_sigaction = handler as usize; }
164163
#[cfg(target_os = "aix")]
165-
let set_handler =
166-
|action: &mut libc::sigaction, handler| action.sa_union.__su_sigaction = handler;
167-
set_handler(&mut new, handler);
164+
{ new.sa_union.__su_sigaction = handler; }
168165
// Android is broken and uses different int types than the rest (and different depending on
169166
// the pointer width). This converts the flags to the proper type no matter what it is on
170167
// the given platform.

src/low_level/pipe.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ use libc::{self, c_int};
8181

8282
use crate::SigId;
8383

84+
#[cfg(target_os = "aix")]
85+
const MSG_NOWAIT: i32 = libc::MSG_NONBLOCK;
86+
#[cfg(not(target_os = "aix"))]
87+
const MSG_NOWAIT: i32 = libc::MSG_DONTWAIT;
88+
8489
#[derive(Copy, Clone)]
8590
pub(crate) enum WakeMethod {
8691
Send,
@@ -141,10 +146,7 @@ pub(crate) fn wake(pipe: RawFd, method: WakeMethod) {
141146
let data = b"X" as *const _ as *const _;
142147
match method {
143148
WakeMethod::Write => libc::write(pipe, data, 1),
144-
#[cfg(target_os = "aix")]
145-
WakeMethod::Send => libc::send(pipe, data, 1, libc::MSG_NONBLOCK),
146-
#[cfg(not(target_os = "aix"))]
147-
WakeMethod::Send => libc::send(pipe, data, 1, libc::MSG_DONTWAIT),
149+
WakeMethod::Send => libc::send(pipe, data, 1, MSG_NOWAIT),
148150
};
149151
}
150152
}
@@ -173,10 +175,7 @@ pub(crate) fn wake(pipe: RawFd, method: WakeMethod) {
173175
/// * If it is not possible, the [`O_NONBLOCK`][libc::O_NONBLOCK] will be set on the file
174176
/// descriptor and [`write`][libc::write] will be used instead.
175177
pub fn register_raw(signal: c_int, pipe: RawFd) -> Result<SigId, Error> {
176-
#[cfg(not(target_os = "aix"))]
177-
let res = unsafe { libc::send(pipe, &[] as *const _, 0, libc::MSG_DONTWAIT) };
178-
#[cfg(target_os = "aix")]
179-
let res = unsafe { libc::send(pipe, &[] as *const _, 0, libc::MSG_NONBLOCK) };
178+
let res = unsafe { libc::send(pipe, &[] as *const _, 0, MSG_NOWAIT) };
180179
let fd = match (res, Error::last_os_error().kind()) {
181180
(0, _) | (-1, ErrorKind::WouldBlock) => WakeFd {
182181
fd: pipe,

src/low_level/signal_details.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,14 @@ fn restore_default(signal: c_int) -> Result<(), Error> {
112112
// A C structure, supposed to be memset to 0 before use.
113113
let mut action: libc::sigaction = mem::zeroed();
114114
#[cfg(target_os = "aix")]
115-
let set_action = |action: &mut libc::sigaction, sigaction| {
115+
{
116116
action.sa_union.__su_sigaction = mem::transmute::<
117117
usize,
118118
extern "C" fn(libc::c_int, *mut libc::siginfo_t, *mut libc::c_void),
119-
>(sigaction)
120-
};
119+
>(libc::SIG_DFL);
120+
}
121121
#[cfg(not(target_os = "aix"))]
122-
let set_action =
123-
|action: &mut libc::sigaction, sigaction| action.sa_sigaction = sigaction as _;
124-
set_action(&mut action, libc::SIG_DFL);
122+
{ action.sa_sigaction = libc::SIG_DFL as _; }
125123
if libc::sigaction(signal, &action, ptr::null_mut()) == 0 {
126124
Ok(())
127125
} else {

0 commit comments

Comments
 (0)