Avoid using libc::sigemptyset on Android
This commit is contained in:
parent
b45c631382
commit
24be89980e
@ -417,12 +417,26 @@ macro_rules! t {
|
||||
}
|
||||
}
|
||||
|
||||
// Android with api less than 21 define sig* functions inline, so it is not
|
||||
// available for dynamic link. Implementing sigemptyset and sigaddset allow us
|
||||
// to support older Android version (independent of libc version).
|
||||
// The following implementations are based on https://git.io/vSkNf
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
extern {
|
||||
#[cfg_attr(target_os = "netbsd", link_name = "__sigemptyset14")]
|
||||
fn sigemptyset(set: *mut libc::sigset_t) -> libc::c_int;
|
||||
|
||||
#[cfg_attr(target_os = "netbsd", link_name = "__sigaddset14")]
|
||||
fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
unsafe fn sigemptyset(set: *mut libc::sigset_t) -> libc::c_int {
|
||||
libc::memset(set as *mut _, 0, mem::size_of::<libc::sigset_t>());
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
unsafe fn sigaddset(set: *mut libc::sigset_t, signum: libc::c_int) -> libc::c_int {
|
||||
use slice;
|
||||
@ -450,7 +464,7 @@ fn test_process_mask() {
|
||||
|
||||
let mut set: libc::sigset_t = mem::uninitialized();
|
||||
let mut old_set: libc::sigset_t = mem::uninitialized();
|
||||
t!(cvt(libc::sigemptyset(&mut set)));
|
||||
t!(cvt(sigemptyset(&mut set)));
|
||||
t!(cvt(sigaddset(&mut set, libc::SIGINT)));
|
||||
t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set, &mut old_set)));
|
||||
|
||||
|
@ -193,7 +193,16 @@ macro_rules! t {
|
||||
// need to clean things up now to avoid confusing the program
|
||||
// we're about to run.
|
||||
let mut set: libc::sigset_t = mem::uninitialized();
|
||||
t!(cvt(libc::sigemptyset(&mut set)));
|
||||
if cfg!(target_os = "android") {
|
||||
// Implementing sigemptyset allow us to support older Android
|
||||
// versions. See the comment about Android and sig* functions in
|
||||
// process_common.rs
|
||||
libc::memset(&mut set as *mut _ as *mut _,
|
||||
0,
|
||||
mem::size_of::<libc::sigset_t>());
|
||||
} else {
|
||||
t!(cvt(libc::sigemptyset(&mut set)));
|
||||
}
|
||||
t!(cvt(libc::pthread_sigmask(libc::SIG_SETMASK, &set,
|
||||
ptr::null_mut())));
|
||||
let ret = sys::signal(libc::SIGPIPE, libc::SIG_DFL);
|
||||
|
Loading…
Reference in New Issue
Block a user