Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Fix Ctrl+C handling #158

Merged
merged 1 commit into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ fn notmain() -> Result<i32, anyhow::Error> {
// Register a signal handler that sets `exit` to `true` on Ctrl+C. On the second Ctrl+C, the
// signal's default action will be run.
let exit = Arc::new(AtomicBool::new(false));
signal_hook::flag::register_conditional_default(signal::SIGINT, exit.clone())?;
let sigid = signal_hook::flag::register(signal::SIGINT, exit.clone())?;

let sess = Arc::new(Mutex::new(sess));
let mut logging_channel = setup_logging_channel(rtt_addr, sess.clone())?;
Expand Down Expand Up @@ -502,6 +502,12 @@ fn notmain() -> Result<i32, anyhow::Error> {
}
drop(stdout);

// Make any incoming SIGINT terminate the process.
// Due to https://github.com/vorner/signal-hook/issues/97, this will result in SIGABRT, but you
// only need to Ctrl+C here if the backtrace hangs, so that should be fine.
signal_hook::low_level::unregister(sigid);
signal_hook::flag::register_conditional_default(signal::SIGINT, exit.clone())?;

let mut sess = sess.lock().unwrap();
let mut core = sess.core(0)?;

Expand Down