From b3a8dc936c007e72a3580a55864dfda97a675b3c Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 13 Oct 2016 23:43:08 -0700 Subject: cleanup libs; switch to slog logging --- Cargo.lock | 160 ++++++++++--------------------------------- Cargo.toml | 7 +- src/bin/einhyrningsinsctl.rs | 3 - src/main.rs | 120 +++++++++++++++++++++----------- 4 files changed, 117 insertions(+), 173 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4ed9eae..804b6a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,26 +4,15 @@ version = "0.1.0" dependencies = [ "chan 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "chan-signal 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "json 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "nix 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustyline 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slog-envlogger 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "slog-syslog 1.0.0-alpha8 (registry+https://github.com/rust-lang/crates.io-index)", + "slog-term 1.1.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)", - "url 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "aho-corasick" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -83,40 +72,16 @@ dependencies = [ "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crossbeam" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "encode_unicode" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "env_logger" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.77 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "getopts" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "idna" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "isatty" version = "0.1.1" @@ -146,11 +111,6 @@ name = "lazy_static" version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "lazy_static" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "libc" version = "0.2.16" @@ -162,25 +122,25 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "matches" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "memchr" -version = "0.1.11" +name = "nix" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "nix" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -236,23 +196,6 @@ dependencies = [ "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "regex" -version = "0.1.77" -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.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.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "rustc_version" version = "0.1.7" @@ -285,47 +228,45 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "slog-envlogger" -version = "0.5.0" +name = "slog-stream" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.77 (registry+https://github.com/rust-lang/crates.io-index)", "slog 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slog-stdlog 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slog-term 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "slog-stdlog" -version = "1.0.1" +name = "slog-syslog" +version = "1.0.0-alpha8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slog-term 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "slog-stream 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syslog 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "slog-stream" +name = "slog-term" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)", + "isatty 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "slog 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "slog-stream 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "slog-term" -version = "1.1.0" +name = "syslog" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)", - "isatty 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slog 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slog-stream 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -363,38 +304,20 @@ dependencies = [ "chrono 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "unicode-bidi" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "matches 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "unicode-normalization" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "unicode-width" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "url" -version = "1.2.1" +name = "unix_socket" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "matches 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "utf8-ranges" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "void" version = "1.0.2" @@ -411,7 +334,6 @@ 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" @@ -420,46 +342,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum chan-signal 0.1.6 (git+https://github.com/bnewbold/chan-signal)" = "" "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 crossbeam 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0c5ea215664ca264da8a9d9c3be80d2eaf30923c259d03e870388eb927508f97" "checksum encode_unicode 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "28d65f1f5841ef7c6792861294b72beda34c664deb8be27970f36c306b7da1ce" -"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 idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1053236e00ce4f668aeca4a769a09b3bf5a682d802abd6f3cb39374f6b162c11" "checksum isatty 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7408a548dc0e406b7912d9f84c261cc533c1866e047644a811c133c56041ac0c" "checksum json 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "772d39b38286c6ebeb2c0412a8d03afd81c3c3ba0046571b9ce9c2ef64475698" "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 lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49247ec2a285bb3dcb23cbd9c35193c025e7251bfce77c1d5da97e6362dffe7f" "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 matches 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc3ad8109fa4b522f9b0cd81440422781f564aaf8c195de6b9d6642177ad0dd" -"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" "checksum nix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bfb3ddedaa14746434a02041940495bf11325c22f6d36125d3bdd56090d50a79" +"checksum nix 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a7bb1da2be7da3cbffda73fc681d509ffd9e665af478d2bee1907cee0bc64b2" "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 rustyline 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00b06ac9c8e8e3e83b33d175d39a9f7b6c2c930c82990593719c8e48788ae2d9" "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" "checksum slog 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d816659be2527f0f85437f31ebd3bea98a2553f83c41a6404abae9f530c9ab62" -"checksum slog-envlogger 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfea715bb310c33c8f90e659bce5b95e39851348b9a7e2a77495a069662def78" -"checksum slog-stdlog 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9c50950e13491ed54f1417bdfdf572f38d9b6d597c48d865ac155fa49fe5357f" "checksum slog-stream 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "33e181e37e13b935f2f2f6a01edf143ebd3520915b46528678024bf34df3b922" +"checksum slog-syslog 1.0.0-alpha8 (registry+https://github.com/rust-lang/crates.io-index)" = "c4356ac9c84f63034aac82b73215690f9e1070a332580919162f0e543fed6e97" "checksum slog-term 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "04d9d55d8d57a200c9b676f8113a8e185d01fffa891961fa7f2804711423f27e" +"checksum syslog 3.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a31ba3a519b8e17760a5f4d821403fa62de0cb6a530a993696a5abf6f3abc93a" "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 unicode-bidi 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c1f7ceb96afdfeedee42bade65a0d585a6a0106f681b6749c8ff4daa8df30b3f" -"checksum unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "26643a2f83bac55f1976fb716c10234485f9202dcd65cfbdf9da49867b271172" "checksum unicode-width 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2d6722facc10989f63ee0e20a83cd4e1714a9ae11529403ac7e0afd069abc39e" -"checksum url 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8527c62d9869a08325c38272b3f85668df22a65890c61a639d233dc0ed0b23a2" -"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" +"checksum unix_socket 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6aa2700417c405c38f5e6902d699345241c28c0b7ade4abaad71e35a87eb1564" "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 795ff18..7f6e03f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,18 +5,15 @@ authors = ["bnewbold "] [dependencies] nix = "0.7" -log = "0.3" -env_logger = "0.3" getopts = "^0.2" timer = "0.1" time = "0.1" -chrono = "0.2" chan = "0.1" chan-signal = "0.1" slog = "1.0" -slog-envlogger = "0.5" +slog-term = "1.1" +slog-syslog = "1.0.0-alpha" json = "*" -url = "1.2" rustyline = "1.0" [replace] diff --git a/src/bin/einhyrningsinsctl.rs b/src/bin/einhyrningsinsctl.rs index a727c2f..03d6d51 100644 --- a/src/bin/einhyrningsinsctl.rs +++ b/src/bin/einhyrningsinsctl.rs @@ -20,13 +20,10 @@ extern crate json; extern crate getopts; -extern crate log; -extern crate env_logger; extern crate nix; extern crate timer; extern crate time; extern crate chan_signal; -extern crate url; extern crate rustyline; use std::io; diff --git a/src/main.rs b/src/main.rs index eb3dc9c..0120599 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,18 +16,16 @@ * along with this program. If not, see . */ -#[macro_use] -extern crate chan; +#[macro_use] extern crate chan; +#[macro_use] extern crate slog; +extern crate slog_syslog; +extern crate slog_term; extern crate json; - extern crate getopts; -extern crate log; -extern crate env_logger; extern crate nix; extern crate timer; extern crate time; extern crate chan_signal; -extern crate url; use std::io::prelude::*; use std::io::{BufReader, BufWriter}; @@ -44,13 +42,14 @@ use std::net::TcpListener; use std::net::ToSocketAddrs; use std::os::unix::net::{UnixStream, UnixListener}; use std::thread; +use std::os::unix::io::{RawFd, IntoRawFd}; use time::Duration; use std::collections::HashMap; use getopts::Options; use chan_signal::Signal; use chan::{Sender, Receiver}; -use std::os::unix::io::{RawFd, IntoRawFd}; +use slog::DrainExt; #[derive(Clone, Debug, PartialEq)] @@ -67,6 +66,8 @@ struct EinConfig { ctrl_path: String, bind_slugs: Vec, env_drops: Vec, + verbose: bool, + syslog: bool, } struct EinState { @@ -76,6 +77,7 @@ struct EinState { timer: timer::Timer, timer_tx: Sender, timer_rx: Receiver, + log: slog::Logger, } #[derive(Copy, Clone, Debug, PartialEq)] @@ -116,6 +118,7 @@ struct Offspring { attempts: u64, timer_guard: Option, replaces: Option, + log: slog::Logger, } impl Offspring { @@ -127,12 +130,15 @@ impl Offspring { attempts: 0, timer_guard: None, replaces: None, + log: state.log.clone(), }; let pid = o.process.id(); + o.log = state.log.new(o!("child_pid" => pid,)); let t_tx = state.timer_tx.clone(); o.timer_guard = Some(state.timer.schedule_with_delay(state.cfg.childhood, move || { t_tx.send(TimerAction::CheckAlive(pid)); })); + info!(o.log, "spawned"); Ok(o) } @@ -195,7 +201,11 @@ impl Offspring { Signal::USR2 => nix::sys::signal::Signal::SIGUSR2, Signal::STOP => nix::sys::signal::Signal::SIGSTOP, Signal::CONT => nix::sys::signal::Signal::SIGCONT, - _ => { println!("Unexpected signal: {:?}", sig); return; }, + _ => { + warn!(self.log, "tried to send unexpected signal"; + "signal" => format!("{:?}", sig)); + return; + }, }; nix::sys::signal::kill(self.process.id() as i32, nix_sig).unwrap(); } @@ -210,7 +220,6 @@ fn shepard(mut state: EinState, signal_rx: Receiver) { let o = Offspring::spawn(&mut state).unwrap(); let pid = o.process.id(); brood.insert(pid, o); - println!("Spawned: {}", pid); } // Ugh, see: http://burntsushi.net/rustdoc/chan/macro.chan_select.html#failure-modes @@ -228,7 +237,7 @@ fn shepard(mut state: EinState, signal_rx: Receiver) { if let Some(mut o) = brood.remove(&pid) { if !state.cfg.manual_ack && o.state == OffspringState::Infancy { if o.is_active() { - println!("{} found to be alive", pid); + debug!(o.log, "found to be alive"); o.state = OffspringState::Healthy; if let Some(old_pid) = o.replaces { if let Some(old) = brood.get_mut(&old_pid) { @@ -237,9 +246,11 @@ fn shepard(mut state: EinState, signal_rx: Receiver) { } } } else if state.cfg.manual_ack && o.state == OffspringState::Infancy { - println!("{} didn't check in", pid); + warn!(o.log, "didn't ack in time, not healthy"; + "max_retries" => state.cfg.retries, + "attempts" => o.attempts); if o.attempts + 1 >= state.cfg.retries { - println!("Ran out of retries..."); + warn!(o.log, "ran out of retries"); } else { let mut successor = o.respawn(&mut state).unwrap(); successor.attempts = o.attempts + 1; @@ -247,7 +258,8 @@ fn shepard(mut state: EinState, signal_rx: Receiver) { } o.terminate(&mut state); } else { - println!("Unexpected CheckAlive state! pid={} state={:?}", o.process.id(), o.state); + warn!(o.log, "Unexpected CheckAlive state!"; + "state" => format!("{:?}", o.state)); } brood.insert(pid, o); }; @@ -346,11 +358,12 @@ fn shepard(mut state: EinState, signal_rx: Receiver) { match res { Ok(nix::sys::wait::WaitStatus::Exited(pid, _)) | Ok(nix::sys::wait::WaitStatus::Signaled(pid, _, _)) => { - println!("PID {} exited", pid); + info!(state.log, "child exited"; "child_pid" => pid); if let Some(mut o) = brood.remove(&(pid as u32)) { match o.state { OffspringState::Infancy => { if o.attempts + 1 >= state.cfg.retries { - println!("Ran out of retries..."); + warn!(state.log, "ran out of retries while spawning"; + "child_pid" => pid); } else { let mut successor = o.respawn(&mut state).unwrap(); successor.attempts = o.attempts + 1; @@ -364,21 +377,24 @@ fn shepard(mut state: EinState, signal_rx: Receiver) { }, OffspringState::Notified => (), OffspringState::Dead => { - println!("ERR: double-notified death on {}", pid); + error!(state.log, "double-notified death"; + "child_pid" => pid); } } }; }, Ok(nix::sys::wait::WaitStatus::StillAlive) => break, Ok(_) => { - println!("Some other thing we don't care about happened: {:?}", res); + info!(state.log, "SIGCHLD we don't care about"; + "value" => format!("{:?}", res)); }, Err(nix::Error::Sys(nix::Errno::ECHILD)) => { - println!("all children are dead, bailing"); + warn!(state.log, "all children are dead, bailing"); run = false; break; }, Err(e) => { - println!("waitpid err: {}", e); + error!(state.log, "waitpid error"; + "err" => format!("{:?}", e)); break; }, } @@ -398,39 +414,45 @@ fn shepard(mut state: EinState, signal_rx: Receiver) { brood.insert(successor.process.id(), successor); } }, Signal::TTIN | Signal::TTOU | Signal::USR1 | Signal::STOP | Signal::CONT => { - println!("Passing signal to children: {:?}", sig.unwrap()); + let sig = sig.unwrap(); + info!(state.log, "passing signal to children"; + "signal" => format!("{:?}", sig)); for (_, o) in brood.iter_mut() { - o.signal(sig.unwrap()); + o.signal(sig); } }, Signal::INT | Signal::USR2 => { - println!("Exiting! Gracefully shutting down children first, but won't wait."); + info!(state.log, + "Exiting! Gracefully shutting down children first, but won't wait"); for (_, o) in brood.iter_mut() { o.shutdown(&mut state); } run = false; }, Signal::TERM | Signal::QUIT => { - println!("Exiting! Killing children first, but won't wait."); + info!(state.log, + "Exiting! Killing children first, but won't wait."); for (_, o) in brood.iter_mut() { o.terminate(&mut state); } run = false; }, default => { - println!("Unexpected signal: {:?} (ignoring)", default); + info!(state.log, "Unexpected signal (ignoring)"; + "signal" => format!("{:?}", default)); }, }, } if !run { break; } } - println!("Reaping children... (count={})", brood.len()); + info!(state.log, "reaping children"; + "count" => brood.len()); for (pid, o) in brood.iter() { if o.is_active() { nix::sys::wait::waitpid(*pid as i32, Some(nix::sys::wait::WNOHANG)).ok(); } } - println!("Done."); + info!(state.log, "done, exiting"); } /* * * * * * * * Setup and CLI * * * * * * * */ @@ -450,6 +472,7 @@ fn main() { opts.optflag("h", "help", "print this help menu"); opts.optflag("", "version", "print the version"); opts.optflag("v", "verbose", "more debugging messages"); + opts.optflag("", "syslog", "enables syslog-ing (for WARN and above)"); opts.optflag("4", "ipv4-only", "only accept IPv4 connections"); opts.optflag("6", "ipv6-only", "only accept IPv6 connections"); opts.optflag("m", "manual", "manual (explicit) acknowledge mode"); @@ -497,6 +520,8 @@ fn main() { let ipv4_only = matches.opt_present("4"); let ipv6_only = matches.opt_present("6"); let manual_ack = matches.opt_present("m"); + let verbose = matches.opt_present("verbose"); + let syslog = matches.opt_present("syslog"); let program_and_args = if !matches.free.is_empty() { matches.free @@ -518,6 +543,8 @@ fn main() { ctrl_path: path_str, bind_slugs: bind_slugs, env_drops: env_drops, + verbose: verbose, + syslog: syslog, }; // Control socket first; not same scope as other state @@ -556,7 +583,8 @@ fn main() { }; //// Start Constrol Socket Thread - thread::spawn(move || ctrl_socket_serve(ctrl_listener, ctrl_req_tx)); + let ctrl_log = state.log.clone(); + thread::spawn(move || ctrl_socket_serve(ctrl_listener, ctrl_req_tx, ctrl_log)); //// State Event Loop shepard(state, signal_rx); @@ -566,6 +594,18 @@ fn main() { // Initializes config into state fn init(cfg: EinConfig, ctrl_req_rx: Receiver) -> Result { + //// Configure logging + let term_drain = slog::level_filter( + if cfg.verbose { slog::Level::Debug } else { slog::Level::Info }, + slog_term::streamer().async().auto_color().compact().build()); + let syslog_drain = slog::level_filter( + slog::Level::Warning, + slog_syslog::unix_3164(slog_syslog::Facility::LOG_DAEMON)); + // XXX: cfg.syslog + let log_root = slog::Logger::root( + slog::duplicate(term_drain, syslog_drain).ignore_err(), + o!("version" => env!("CARGO_PKG_VERSION"))); + // These will be tuples: (SocketAddr, SO_REUSEADDR, O_NONBLOCK) let sock_confs: Vec<(SocketAddr, bool, bool)> = cfg.bind_slugs.iter().map(|b| { let mut r = false; @@ -595,14 +635,6 @@ fn init(cfg: EinConfig, ctrl_req_rx: Receiver) -> Result = sock_confs.iter().map(|t| { let sa = t.0; let r = t.1; let n = t.2; // ugly (TcpListener::bind(sa).unwrap(), r, n) @@ -625,7 +657,9 @@ fn init(cfg: EinConfig, ctrl_req_rx: Receiver) -> Result fd, + "FD_CLOEXEC" => nix::fcntl::fcntl(fd, nix::fcntl::FcntlArg::F_GETFD).unwrap()); fd }).collect(); @@ -646,6 +680,7 @@ fn init(cfg: EinConfig, ctrl_req_rx: Receiver) -> Result) { +fn ctrl_socket_handle(stream: UnixStream, ctrl_req_tx: Sender, log: slog::Logger) { let reader = BufReader::new(&stream); let mut writer = BufWriter::new(&stream); for rawline in reader.lines() { let rawline = rawline.unwrap(); - println!("Got line: {}", rawline); + debug!(log, "got raw command"; "line" => rawline); if rawline.len() == 0 { continue; } @@ -753,16 +788,19 @@ fn ctrl_socket_handle(stream: UnixStream, ctrl_req_tx: Sender) { stream.shutdown(std::net::Shutdown::Both).unwrap(); } -fn ctrl_socket_serve(listener: UnixListener, ctrl_req_tx: Sender) { +fn ctrl_socket_serve(listener: UnixListener, ctrl_req_tx: Sender, log: slog::Logger) { for conn in listener.incoming() { match conn{ Ok(conn) => { let tx = ctrl_req_tx.clone(); - thread::spawn(move || ctrl_socket_handle(conn, tx)); + let conn_log = log.new(o!( + "client" => format!("{:?}", conn))); + info!(conn_log, "accepted connection"); + thread::spawn(move || ctrl_socket_handle(conn, tx, conn_log)); }, Err(err) => { // TODO - println!("control socket err: {}", err); + error!(log, "control socket err: {}", err); break; }, } -- cgit v1.2.3