aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-10-11 02:17:27 -0700
committerbnewbold <bnewbold@robocracy.org>2016-10-11 02:17:27 -0700
commita68f898fbe9e1c4ed8be5d4bd777e9a42198d3db (patch)
treef3b02ddca8c75b1cbcaf6f10825ce1de160a0637
parent72bea95d8ba781cf1c5641987179b5c45a28f919 (diff)
downloadeinhyrningsins-a68f898fbe9e1c4ed8be5d4bd777e9a42198d3db.tar.gz
einhyrningsins-a68f898fbe9e1c4ed8be5d4bd777e9a42198d3db.zip
more signal handlers
-rw-r--r--src/main.rs42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index 9754ab7..918a37d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -155,11 +155,6 @@ enum TimerAction {
CheckShutdown(u32),
}
-/*
- Result<WaitStatus>
- nix::sys::wait::waitpid
-*/
-
// This is the main event loop
fn shepard(mut cfg: EinConfig, signal_rx: Receiver<Signal>) {
@@ -209,7 +204,7 @@ fn shepard(mut cfg: EinConfig, signal_rx: Receiver<Signal>) {
}
brood.insert(pid, o);
};
- }
+ },
TimerAction::CheckShutdown(pid) => {
if let Some(o) = brood.get_mut(&pid) {
if o.is_active() {
@@ -227,6 +222,41 @@ 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
+ loop {
+ let res = nix::sys::wait::waitpid(-1, Some(nix::sys::wait::WNOWAIT));
+ match res {
+ Ok(nix::sys::wait::WaitStatus::Exited(pid, status)) => {
+ println!("PID {} exited with status {}", pid, status);
+ if let Some(mut o) = brood.remove(&(pid as u32)) { match o.state {
+ OffspringState::Infancy => {
+ if o.attempts + 1 >= cfg.retries {
+ println!("Ran out of retries...");
+ } else {
+ let mut successor = o.respawn(&mut cfg, &mut timer, timer_tx.clone()).unwrap();
+ successor.attempts = o.attempts + 1;
+ brood.insert(successor.process.id(), successor);
+ }
+ },
+ OffspringState::Healthy => {
+ let mut successor = o.respawn(&mut cfg, &mut timer, timer_tx.clone()).unwrap();
+ successor.replaces = Some(pid as u32);
+ brood.insert(successor.process.id(), successor);
+ },
+ OffspringState::Notified => (),
+ OffspringState::Dead => {
+ println!("ERR: double-notified death on {}", pid);
+ }
+ } };
+ },
+ Ok(_) => {
+ println!("Some other thing we don't care about happened: {:?}", res);
+ },
+ Err(e) => {
+ println!("waitpid err: {}", e);
+ break;
+ },
+ }
+ };
},
Signal::HUP => {
for (_, o) in brood.iter_mut() {