Skip to content

Commit c4234db

Browse files
committed
sh: fix build errors on mac
1 parent 5d9e753 commit c4234db

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

sh/os/errno.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ impl TryFrom<libc::c_int> for Errno {
406406
}
407407

408408
pub fn get_current_errno_value() -> Errno {
409-
let errno = unsafe { *libc::__errno_location() };
409+
// guaranteed to be some, unwrap is safe
410+
let errno = std::io::Error::last_os_error().raw_os_error().unwrap();
410411
errno.try_into().expect("invalid errno value")
411412
}

sh/os/signals.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,14 @@ fn get_pending_signal() -> Option<Signal> {
270270
}
271271

272272
unsafe fn handle_signal(signal: Signal, handler: libc::sighandler_t) {
273-
let mut empty_sigset: libc::sigset_t = std::mem::zeroed::<libc::sigset_t>();
273+
// sigaction contains different field on different systems, we can't
274+
// initialize it directly
275+
let mut action = std::mem::zeroed::<libc::sigaction>();
276+
action.sa_sigaction = handler;
274277
// never fails
275-
libc::sigemptyset(&mut empty_sigset);
278+
libc::sigemptyset(&mut action.sa_mask);
279+
action.sa_flags = libc::SA_SIGINFO;
276280

277-
let action = libc::sigaction {
278-
sa_sigaction: handler,
279-
sa_mask: empty_sigset,
280-
sa_flags: libc::SA_SIGINFO,
281-
sa_restorer: None,
282-
};
283281
let result = libc::sigaction(signal.into(), &action, std::ptr::null_mut());
284282
if result < 0 {
285283
panic!("failed to set signal handler")

0 commit comments

Comments
 (0)