aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock56
-rw-r--r--Cargo.toml9
-rw-r--r--src/main.rs25
3 files changed, 68 insertions, 22 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a71cde7..f85d35f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -11,7 +11,6 @@ dependencies = [
"nix 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"timer 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "uuid 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -56,7 +55,7 @@ dependencies = [
[[package]]
name = "chan-signal"
version = "0.1.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+source = "git+https://github.com/bnewbold/chan-signal#bc3ab7a23b518a47f72f1e9f4b7d169286edd862"
dependencies = [
"bit-set 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"chan 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -65,6 +64,12 @@ dependencies = [
]
[[package]]
+name = "chan-signal"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+replace = "chan-signal 0.1.6 (git+https://github.com/bnewbold/chan-signal)"
+
+[[package]]
name = "chrono"
version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -179,14 +184,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
- "regex-syntax 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "regex-syntax 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
-version = "0.3.5"
+version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -243,14 +248,6 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
-name = "uuid"
-version = "0.2.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -265,3 +262,38 @@ name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
+[metadata]
+"checksum aho-corasick 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ca972c2ea5f742bfce5687b9aef75506a764f61d37f8f649047846a9686ddb66"
+"checksum bit-set 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e6e1e6fb1c9e3d6fcdec57216a74eaa03e41f52a22f13a16438251d8e88b89da"
+"checksum bit-vec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5b97c2c8e8bbb4251754f559df8af22fb264853c7d009084a576cdf12565089d"
+"checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3"
+"checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c"
+"checksum chan 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "82b22acfef7960fd8f829bc50749273be637cbd76b9d4cc20497666cc3a33329"
+"checksum chan-signal 0.1.6 (git+https://github.com/bnewbold/chan-signal)" = "<none>"
+"checksum chan-signal 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "afbba6202dc1d10ff08c3b04e00e4d2d6cf5effee56cd9fee92928be6692379a"
+"checksum chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9213f7cd7c27e95c2b57c49f0e69b1ea65b27138da84a170133fd21b07659c00"
+"checksum env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "15abd780e45b3ea4f76b4e9a26ff4843258dd8a3eed2775a0e7368c2e7936c2f"
+"checksum getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9047cfbd08a437050b363d35ef160452c5fe8ea5187ae0a624708c91581d685"
+"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
+"checksum lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "cf186d1a8aa5f5bee5fd662bc9c1b949e0259e1bcc379d1f006847b0080c7417"
+"checksum libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "408014cace30ee0f767b1c4517980646a573ec61a57957aeeabcac8ac0a02e8d"
+"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
+"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"
+"checksum nix 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0d95c5fa8b641c10ad0b8887454ebaafa3c92b5cd5350f8fc693adafd178e7b"
+"checksum num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "bde7c03b09e7c6a301ee81f6ddf66d7a28ec305699e3d3b056d2fc56470e3120"
+"checksum num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "fb24d9bfb3f222010df27995441ded1e954f8f69cd35021f6bef02ca9552fb92"
+"checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c"
+"checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c"
+"checksum rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "2791d88c6defac799c3f20d74f094ca33b9332612d9aef9078519c82e4fe04a5"
+"checksum regex 0.1.77 (registry+https://github.com/rust-lang/crates.io-index)" = "64b03446c466d35b42f2a8b203c8e03ed8b91c0f17b56e1f84f7210a257aa665"
+"checksum regex-syntax 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "48f0573bcee95a48da786f8823465b5f2a1fae288a55407aca991e5b3e0eae11"
+"checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084"
+"checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
+"checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03"
+"checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5"
+"checksum time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7ec6d62a20df54e07ab3b78b9a3932972f4b7981de295563686849eb3989af"
+"checksum timer 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a9522a9ec40055e2f9e514e38d2415a496e81dbfc1ece15d98d2fe55c44946b3"
+"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f"
+"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
+"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
+"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
diff --git a/Cargo.toml b/Cargo.toml
index 4896865..fec9e07 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,5 +13,10 @@ time = "0.1"
chrono = "0.2"
chan = "0.1"
chan-signal = "0.1"
-uuid = { version = "0.2", features = ["v4"] }
-# XXX: num = "0.1"
+#slog = "1.0"
+#slog-envlogger = "0.5"
+#jsonrpc-core = "3.0"
+
+[replace]
+"chan-signal:0.1.6" = { git = 'https://github.com/bnewbold/chan-signal' }
+
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]);