aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-07-16 11:40:10 +0000
committerFuwn <[email protected]>2021-07-16 11:40:10 +0000
commit4ee4b487e6dbcbd793939c74f38d4e9422d6269c (patch)
treee1c4a6c58114695918a437f1f44b21a6347edb39
parentbuild(make): create kill task (diff)
downloadwhirl-4ee4b487e6dbcbd793939c74f38d4e9422d6269c.tar.xz
whirl-4ee4b487e6dbcbd793939c74f38d4e9422d6269c.zip
fix(cli): proper ctrl+c handling
-rw-r--r--crates/whirl/Cargo.toml1
-rw-r--r--crates/whirl/src/lib.rs12
2 files changed, 13 insertions, 0 deletions
diff --git a/crates/whirl/Cargo.toml b/crates/whirl/Cargo.toml
index ef2308e..d6cb49c 100644
--- a/crates/whirl/Cargo.toml
+++ b/crates/whirl/Cargo.toml
@@ -37,6 +37,7 @@ serde_derive = "1.0.126"
# CLI
structopt = "0.3.22"
+signal-hook = "0.3.9"
# Config
whirl_config = { path = "../whirl_config" }
diff --git a/crates/whirl/src/lib.rs b/crates/whirl/src/lib.rs
index 9297ccc..1e3931c 100644
--- a/crates/whirl/src/lib.rs
+++ b/crates/whirl/src/lib.rs
@@ -38,6 +38,7 @@ static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
pub mod cli;
+use signal_hook::consts::{SIGINT, SIGTERM};
use whirl_config::Config;
pub struct Whirl;
@@ -78,6 +79,17 @@ impl Whirl {
}
}
+ // Ctrl+C handling
+ tokio::spawn(async move {
+ for signal in signal_hook::iterator::Signals::new(&[SIGTERM, SIGINT])
+ .unwrap()
+ .forever()
+ {
+ info!("signal received: {:?}, killing whirl", signal);
+ std::process::exit(0);
+ }
+ });
+
crate::cli::Cli::execute().await;
Ok(())