pass lua exit status or signal to client
This commit is contained in:
+3
-3
@@ -37,7 +37,7 @@ fn main() {
|
||||
let buf = IoSlice::new(&payload);
|
||||
sock.send_vectored_with_ancillary(&[buf], &mut ancillary).expect("send failed");
|
||||
|
||||
let mut buf = vec![0u8; 1];
|
||||
let _ = sock.recv(buf.as_mut_slice()).unwrap();
|
||||
exit(buf[0].into());
|
||||
let mut buf : [u8; 4] = [0,0,0,0];
|
||||
let _ = sock.recv(&mut buf).unwrap();
|
||||
exit(i32::from_be_bytes(buf));
|
||||
}
|
||||
|
||||
+13
-26
@@ -26,7 +26,7 @@ use libc::{
|
||||
POLLIN,
|
||||
c_void
|
||||
};
|
||||
use nix::sys::wait::{wait,WaitStatus};
|
||||
use nix::sys::wait::{wait,WaitStatus::{Exited,Signaled}};
|
||||
|
||||
use fork::{Fork, fork};
|
||||
|
||||
@@ -165,39 +165,26 @@ fn main() -> std::io::Result<()> {
|
||||
}
|
||||
};
|
||||
if pollfds[1].revents > 0 {
|
||||
println!("a child is done");
|
||||
let mut buf = [0u8;1];
|
||||
let _ = sigchild_reader.read(&mut buf);
|
||||
if let Ok(wstatus) = wait() {
|
||||
if let Some(pid) = wstatus.pid() {
|
||||
match peers.get(&pid.as_raw()) {
|
||||
Some(addr) => {
|
||||
println!("send exit bytes {:?}",
|
||||
sock.send_to_addr(b"\0\n\r\t", addr));
|
||||
},
|
||||
None => {
|
||||
println!("no peer for child");
|
||||
match wstatus {
|
||||
Exited(pid, code) => {
|
||||
if let Some(addr) = peers.get(&pid.as_raw()) {
|
||||
sock.send_to_addr(&code.to_be_bytes(), addr);
|
||||
}
|
||||
}
|
||||
},
|
||||
Signaled(pid, sig, _) => {
|
||||
if let Some(addr) = peers.get(&pid.as_raw()) {
|
||||
let ret : u32 = sig as u32 + 128;
|
||||
sock.send_to_addr(&ret.to_be_bytes(), addr);
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
}
|
||||
} else {
|
||||
println!("timeout");
|
||||
}
|
||||
|
||||
// // println!("parent {:?} {:?}", pid, result);
|
||||
// match waitpid(pid) {
|
||||
// Ok(status) => {
|
||||
// println!("exited {:?}", WEXITSTATUS(status));
|
||||
// },
|
||||
// Err(e) => {
|
||||
// println!("waitpid failed {:?}", e);
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user