diff --git a/signal-hook-registry/src/lib.rs b/signal-hook-registry/src/lib.rs index 9dca7c7..e488906 100644 --- a/signal-hook-registry/src/lib.rs +++ b/signal-hook-registry/src/lib.rs @@ -158,7 +158,10 @@ impl Slot { fn new(signal: libc::c_int) -> Result { // C data structure, expected to be zeroed out. let mut new: libc::sigaction = unsafe { mem::zeroed() }; - new.sa_sigaction = handler as usize; + #[cfg(not(target_os = "aix"))] + { new.sa_sigaction = handler as usize; } + #[cfg(target_os = "aix")] + { new.sa_union.__su_sigaction = handler; } // Android is broken and uses different int types than the rest (and different depending on // the pointer width). This converts the flags to the proper type no matter what it is on // the given platform. @@ -232,7 +235,10 @@ impl Prev { #[cfg(not(windows))] unsafe fn execute(&self, sig: c_int, info: *mut siginfo_t, data: *mut c_void) { + #[cfg(not(target_os = "aix"))] let fptr = self.info.sa_sigaction; + #[cfg(target_os = "aix")] + let fptr = self.info.sa_union.__su_sigaction as usize; if fptr != 0 && fptr != libc::SIG_DFL && fptr != libc::SIG_IGN { // Android is broken and uses different int types than the rest (and different // depending on the pointer width). This converts the flags to the proper type no diff --git a/src/iterator/backend.rs b/src/iterator/backend.rs index 8a17082..2ed4bf9 100644 --- a/src/iterator/backend.rs +++ b/src/iterator/backend.rs @@ -309,11 +309,15 @@ where // should not be something like closed file descriptor. It could EAGAIN, but // that's OK in case we say MSG_DONTWAIT. If it's EINTR, then it's OK too, // it'll only create a spurious wakeup. + #[cfg(target_os = "aix")] + let nowait_flag = libc::MSG_NONBLOCK; + #[cfg(not(target_os = "aix"))] + let nowait_flag = libc::MSG_DONTWAIT; while libc::recv( self.read.as_raw_fd(), buff.as_mut_ptr() as *mut libc::c_void, SIZE, - libc::MSG_DONTWAIT, + nowait_flag, ) > 0 {} } diff --git a/src/low_level/pipe.rs b/src/low_level/pipe.rs index e38c833..3cd2187 100644 --- a/src/low_level/pipe.rs +++ b/src/low_level/pipe.rs @@ -81,6 +81,11 @@ use libc::{self, c_int}; use crate::SigId; +#[cfg(target_os = "aix")] +const MSG_NOWAIT: i32 = libc::MSG_NONBLOCK; +#[cfg(not(target_os = "aix"))] +const MSG_NOWAIT: i32 = libc::MSG_DONTWAIT; + #[derive(Copy, Clone)] pub(crate) enum WakeMethod { Send, @@ -141,7 +146,7 @@ pub(crate) fn wake(pipe: RawFd, method: WakeMethod) { let data = b"X" as *const _ as *const _; match method { WakeMethod::Write => libc::write(pipe, data, 1), - WakeMethod::Send => libc::send(pipe, data, 1, libc::MSG_DONTWAIT), + WakeMethod::Send => libc::send(pipe, data, 1, MSG_NOWAIT), }; } } @@ -170,7 +175,7 @@ pub(crate) fn wake(pipe: RawFd, method: WakeMethod) { /// * If it is not possible, the [`O_NONBLOCK`][libc::O_NONBLOCK] will be set on the file /// descriptor and [`write`][libc::write] will be used instead. pub fn register_raw(signal: c_int, pipe: RawFd) -> Result { - let res = unsafe { libc::send(pipe, &[] as *const _, 0, libc::MSG_DONTWAIT) }; + let res = unsafe { libc::send(pipe, &[] as *const _, 0, MSG_NOWAIT) }; let fd = match (res, Error::last_os_error().kind()) { (0, _) | (-1, ErrorKind::WouldBlock) => WakeFd { fd: pipe, diff --git a/src/low_level/signal_details.rs b/src/low_level/signal_details.rs index a8b7017..303f4e4 100644 --- a/src/low_level/signal_details.rs +++ b/src/low_level/signal_details.rs @@ -111,7 +111,15 @@ fn restore_default(signal: c_int) -> Result<(), Error> { unsafe { // A C structure, supposed to be memset to 0 before use. let mut action: libc::sigaction = mem::zeroed(); - action.sa_sigaction = libc::SIG_DFL as _; + #[cfg(target_os = "aix")] + { + action.sa_union.__su_sigaction = mem::transmute::< + usize, + extern "C" fn(libc::c_int, *mut libc::siginfo_t, *mut libc::c_void), + >(libc::SIG_DFL); + } + #[cfg(not(target_os = "aix"))] + { action.sa_sigaction = libc::SIG_DFL as _; } if libc::sigaction(signal, &action, ptr::null_mut()) == 0 { Ok(()) } else {