Skip to content

Commit

Permalink
use ctrlc for cross platform signal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
xmclark committed Aug 20, 2019
1 parent 06d74ef commit f8f0060
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ maintenance = { status = "actively-developed" }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ctrlc = "3.1.3"
tokio = "^0.1"
tokio-executor = "0.1.8"
tokio-threadpool = "0.1.15"
Expand All @@ -46,7 +47,6 @@ backtrace = "0.3.32"
ego-tree = "0.6.0"
lazy_static = "1.3.0"
objekt = "0.1.2"
signal-hook = "0.1.10"
parking_lot = "0.9"


Expand Down
15 changes: 6 additions & 9 deletions src/bastion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use env_logger::Builder;
use futures::future::poll_fn;
use lazy_static::lazy_static;
use log::LevelFilter;
use signal_hook::{iterator::Signals, SIGINT};
use std::panic::AssertUnwindSafe;
use std::sync::Arc;
use parking_lot::Mutex;
Expand Down Expand Up @@ -329,16 +328,14 @@ impl RuntimeManager for Bastion {

fn runtime_shutdown_callback() {
let mut entered = tokio_executor::enter().expect("main thread_local runtime lock");
let signals = Signals::new(&[SIGINT]).unwrap();

let running = Arc::new(AtomicBool::new(true));
let r = running.clone();
let _ = ctrlc::set_handler(move || {
r.store(false, Ordering::SeqCst);
}).unwrap();
entered
.block_on(poll_fn(|| {
for sig in signals.forever() {
match sig {
signal_hook::SIGINT => break,
_ => unreachable!(),
}
}
while running.load(Ordering::SeqCst) {}
CLOSE_OVER
}))
.expect("cannot shutdown");
Expand Down

0 comments on commit f8f0060

Please sign in to comment.