aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-10-11 02:53:18 -0700
committerbnewbold <bnewbold@robocracy.org>2016-10-11 02:53:18 -0700
commit1a04aa6f963b7d20cbcfbce05a87e2c0287297e4 (patch)
tree081681c6ef2afb5c84a367bbc70a53b03f266da5 /src
parenta68f898fbe9e1c4ed8be5d4bd777e9a42198d3db (diff)
downloadeinhyrningsins-1a04aa6f963b7d20cbcfbce05a87e2c0287297e4.tar.gz
einhyrningsins-1a04aa6f963b7d20cbcfbce05a87e2c0287297e4.zip
more work in progress
Diffstat (limited to 'src')
-rw-r--r--src/main.rs25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index 918a37d..4e994c3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -172,6 +172,7 @@ fn shepard(mut cfg: EinConfig, signal_rx: Receiver<Signal>) {
}
//// infinite select() loop over timers, signals
+ let mut run = true;
loop {
chan_select! {
timer_rx.recv() -> action => match action.expect("Error with timer thread") {
@@ -221,12 +222,13 @@ fn shepard(mut cfg: EinConfig, signal_rx: Receiver<Signal>) {
},
},
signal_rx.recv() -> sig => match sig.expect("Error with signal handler") {
- Signal::USR1 => { // USING AS PLACEHOLDER FOR SIGCHLD
+ Signal::CHLD => {
loop {
- let res = nix::sys::wait::waitpid(-1, Some(nix::sys::wait::WNOWAIT));
+ let res = nix::sys::wait::waitpid(-1, Some(nix::sys::wait::WNOHANG));
match res {
- Ok(nix::sys::wait::WaitStatus::Exited(pid, status)) => {
- println!("PID {} exited with status {}", pid, status);
+ Ok(nix::sys::wait::WaitStatus::Exited(pid, _)) |
+ Ok(nix::sys::wait::WaitStatus::Signaled(pid, _, _)) => {
+ println!("PID {} exited", pid);
if let Some(mut o) = brood.remove(&(pid as u32)) { match o.state {
OffspringState::Infancy => {
if o.attempts + 1 >= cfg.retries {
@@ -248,9 +250,15 @@ fn shepard(mut cfg: EinConfig, signal_rx: Receiver<Signal>) {
}
} };
},
+ Ok(nix::sys::wait::WaitStatus::StillAlive) => break,
Ok(_) => {
println!("Some other thing we don't care about happened: {:?}", res);
},
+ Err(nix::Error::Sys(nix::Errno::ECHILD)) => {
+ println!("all children are dead, bailing");
+ run = false;
+ break;
+ },
Err(e) => {
println!("waitpid err: {}", e);
break;
@@ -267,16 +275,17 @@ fn shepard(mut cfg: EinConfig, signal_rx: Receiver<Signal>) {
for (_, o) in brood.iter_mut() {
o.terminate(&mut cfg, &mut timer, timer_tx.clone());
}
- break;
+ run = false;
},
_ => ()
},
}
+ if !run { break; }
}
- println!("Waiting for all children to die");
+ println!("Reaping children... (count={})", brood.len());
for (_, o) in brood.iter_mut() {
- o.process.wait().unwrap();
+ o.process.wait().ok();
}
println!("Done.");
}
@@ -411,7 +420,7 @@ fn main() {
println!("Registering signal handlers...");
let signal_rx = chan_signal::notify(&[Signal::INT,
Signal::TERM,
- //Signal::CHLD, // XXX: PR has been submitted
+ Signal::CHLD, // XXX: PR has been submitted
Signal::USR2,
Signal::HUP]);