mirror of
https://github.com/wez/wezterm.git
synced 2024-12-25 06:12:16 +03:00
add non-linux sigchld waiter
This commit is contained in:
parent
a4b55ecffb
commit
b66f93ad11
@ -10,6 +10,8 @@ use std::mem;
|
||||
use std::os::unix::io::RawFd;
|
||||
use std::ptr;
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
static mut WRITE_END: RawFd = -1;
|
||||
|
||||
pub struct ChildWaiter {
|
||||
fd: RawFd,
|
||||
@ -23,7 +25,38 @@ impl Drop for ChildWaiter {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
extern "C" fn chld_handler(_signo: libc::c_int, _: *const u8, _: *const u8) {
|
||||
unsafe {
|
||||
libc::write(WRITE_END, "x".as_ptr() as *const _, 1);
|
||||
}
|
||||
}
|
||||
|
||||
impl ChildWaiter {
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub fn new() -> Result<ChildWaiter, Error> {
|
||||
unsafe {
|
||||
let mut pipe: [RawFd; 2] = [-1, -1];
|
||||
let res = libc::pipe(pipe.as_mut_ptr());
|
||||
if res == -1 {
|
||||
bail!("pipe failed: {:?}", io::Error::last_os_error());
|
||||
}
|
||||
|
||||
WRITE_END = pipe[1];
|
||||
|
||||
let mut sa: libc::sigaction = mem::zeroed();
|
||||
sa.sa_sigaction = chld_handler as usize;
|
||||
sa.sa_flags = (libc::SA_RESTART | libc::SA_NOCLDSTOP) as _;
|
||||
let res = libc::sigaction(libc::SIGCHLD, &sa, ptr::null_mut());
|
||||
if res == -1 {
|
||||
bail!("sigaction SIGCHLD failed: {:?}", io::Error::last_os_error());
|
||||
}
|
||||
|
||||
Ok(Self { fd: pipe[0] })
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn new() -> Result<ChildWaiter, Error> {
|
||||
unsafe {
|
||||
let mut mask: libc::sigset_t = mem::zeroed();
|
||||
|
Loading…
Reference in New Issue
Block a user