commit f0f7f5d9fa9015558a967bdb06952929109355c8
parent 9f0450b2dd0e2ec5670aa96278d7a3a843985b39
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 30 Apr 2026 21:41:36 +0100
pass lua exit status or signal to client
Diffstat:
2 files changed, 16 insertions(+), 29 deletions(-)
diff --git a/src/bin/luac.rs b/src/bin/luac.rs
@@ -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));
}
diff --git a/src/main.rs b/src/main.rs
@@ -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);
- // }
- // }
- // },
-
-
}
}