Skip to content

Commit 1b8cafa

Browse files
authored
Merge pull request #136 from ecnelises/aix
Support AIX signal handler types
2 parents a4d5e35 + 5dc385f commit 1b8cafa

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

signal-hook-registry/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ impl Slot {
158158
fn new(signal: libc::c_int) -> Result<Self, Error> {
159159
// C data structure, expected to be zeroed out.
160160
let mut new: libc::sigaction = unsafe { mem::zeroed() };
161-
new.sa_sigaction = handler as usize;
161+
#[cfg(not(target_os = "aix"))]
162+
{ new.sa_sigaction = handler as usize; }
163+
#[cfg(target_os = "aix")]
164+
{ new.sa_union.__su_sigaction = handler; }
162165
// Android is broken and uses different int types than the rest (and different depending on
163166
// the pointer width). This converts the flags to the proper type no matter what it is on
164167
// the given platform.
@@ -232,7 +235,10 @@ impl Prev {
232235

233236
#[cfg(not(windows))]
234237
unsafe fn execute(&self, sig: c_int, info: *mut siginfo_t, data: *mut c_void) {
238+
#[cfg(not(target_os = "aix"))]
235239
let fptr = self.info.sa_sigaction;
240+
#[cfg(target_os = "aix")]
241+
let fptr = self.info.sa_union.__su_sigaction as usize;
236242
if fptr != 0 && fptr != libc::SIG_DFL && fptr != libc::SIG_IGN {
237243
// Android is broken and uses different int types than the rest (and different
238244
// depending on the pointer width). This converts the flags to the proper type no

src/iterator/backend.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,15 @@ where
309309
// should not be something like closed file descriptor. It could EAGAIN, but
310310
// that's OK in case we say MSG_DONTWAIT. If it's EINTR, then it's OK too,
311311
// it'll only create a spurious wakeup.
312+
#[cfg(target_os = "aix")]
313+
let nowait_flag = libc::MSG_NONBLOCK;
314+
#[cfg(not(target_os = "aix"))]
315+
let nowait_flag = libc::MSG_DONTWAIT;
312316
while libc::recv(
313317
self.read.as_raw_fd(),
314318
buff.as_mut_ptr() as *mut libc::c_void,
315319
SIZE,
316-
libc::MSG_DONTWAIT,
320+
nowait_flag,
317321
) > 0
318322
{}
319323
}

src/low_level/pipe.rs

+7-2
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,7 +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-
WakeMethod::Send => libc::send(pipe, data, 1, libc::MSG_DONTWAIT),
149+
WakeMethod::Send => libc::send(pipe, data, 1, MSG_NOWAIT),
145150
};
146151
}
147152
}
@@ -170,7 +175,7 @@ pub(crate) fn wake(pipe: RawFd, method: WakeMethod) {
170175
/// * If it is not possible, the [`O_NONBLOCK`][libc::O_NONBLOCK] will be set on the file
171176
/// descriptor and [`write`][libc::write] will be used instead.
172177
pub fn register_raw(signal: c_int, pipe: RawFd) -> Result<SigId, Error> {
173-
let res = unsafe { libc::send(pipe, &[] as *const _, 0, libc::MSG_DONTWAIT) };
178+
let res = unsafe { libc::send(pipe, &[] as *const _, 0, MSG_NOWAIT) };
174179
let fd = match (res, Error::last_os_error().kind()) {
175180
(0, _) | (-1, ErrorKind::WouldBlock) => WakeFd {
176181
fd: pipe,

src/low_level/signal_details.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,15 @@ fn restore_default(signal: c_int) -> Result<(), Error> {
111111
unsafe {
112112
// A C structure, supposed to be memset to 0 before use.
113113
let mut action: libc::sigaction = mem::zeroed();
114-
action.sa_sigaction = libc::SIG_DFL as _;
114+
#[cfg(target_os = "aix")]
115+
{
116+
action.sa_union.__su_sigaction = mem::transmute::<
117+
usize,
118+
extern "C" fn(libc::c_int, *mut libc::siginfo_t, *mut libc::c_void),
119+
>(libc::SIG_DFL);
120+
}
121+
#[cfg(not(target_os = "aix"))]
122+
{ action.sa_sigaction = libc::SIG_DFL as _; }
115123
if libc::sigaction(signal, &action, ptr::null_mut()) == 0 {
116124
Ok(())
117125
} else {

0 commit comments

Comments
 (0)