Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion signal-hook-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,13 @@ impl Slot {
fn new(signal: libc::c_int) -> Result<Self, Error> {
// 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"))]
let set_handler =
|action: &mut libc::sigaction, handler| action.sa_sigaction = handler as usize;
#[cfg(target_os = "aix")]
let set_handler =
|action: &mut libc::sigaction, handler| action.sa_union.__su_sigaction = handler;
set_handler(&mut new, handler);
Copy link
Owner

Choose a reason for hiding this comment

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

Why in this super-complicated way and not just having conditionally-compiled blocks?

// 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.
Expand Down Expand Up @@ -232,7 +238,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
Expand Down
6 changes: 5 additions & 1 deletion src/iterator/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{}
}
Expand Down
6 changes: 6 additions & 0 deletions src/low_level/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ 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),
#[cfg(target_os = "aix")]
WakeMethod::Send => libc::send(pipe, data, 1, libc::MSG_NONBLOCK),
#[cfg(not(target_os = "aix"))]
Copy link
Owner

Choose a reason for hiding this comment

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

I would prefer the same nowait_flag trick here too, to avoid two „same“ calls to duplicate in the code.

WakeMethod::Send => libc::send(pipe, data, 1, libc::MSG_DONTWAIT),
};
}
Expand Down Expand Up @@ -170,7 +173,10 @@ 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<SigId, Error> {
#[cfg(not(target_os = "aix"))]
let res = unsafe { libc::send(pipe, &[] as *const _, 0, libc::MSG_DONTWAIT) };
#[cfg(target_os = "aix")]
let res = unsafe { libc::send(pipe, &[] as *const _, 0, libc::MSG_NONBLOCK) };
Copy link
Owner

Choose a reason for hiding this comment

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

The same as above.

let fd = match (res, Error::last_os_error().kind()) {
(0, _) | (-1, ErrorKind::WouldBlock) => WakeFd {
fd: pipe,
Expand Down
12 changes: 11 additions & 1 deletion src/low_level/signal_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,17 @@ 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")]
let set_action = |action: &mut libc::sigaction, sigaction| {
action.sa_union.__su_sigaction = mem::transmute::<
usize,
extern "C" fn(libc::c_int, *mut libc::siginfo_t, *mut libc::c_void),
>(sigaction)
};
Copy link
Owner

Choose a reason for hiding this comment

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

Doesn't the same sigaction as _ work, only assigning it to a different field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems direct casting from usize to extern fn is not allowed:

error[E0605]: non-primitive cast: `usize` as `extern "C" fn(i32, *mut siginfo_t, *mut c_void)`
   --> src/low_level/signal_details.rs:120:46
    |
120 |             action.sa_union.__su_sigaction = libc::SIG_DFL as _;
    |                                              ^^^^^^^^^^^^^^^^^^ invalid cast

#[cfg(not(target_os = "aix"))]
let set_action =
|action: &mut libc::sigaction, sigaction| action.sa_sigaction = sigaction as _;
set_action(&mut action, libc::SIG_DFL);
if libc::sigaction(signal, &action, ptr::null_mut()) == 0 {
Ok(())
} else {
Expand Down