Skip to content

Commit

Permalink
Runtime process termination on Windows using CTRL-BREAK
Browse files Browse the repository at this point in the history
  • Loading branch information
pwalski committed Jan 11, 2024
1 parent b239421 commit cfb790e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion agent/provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ strum = "0.24"
strum_macros = "0.24"
sys-info = "0.8.0"
thiserror = "1.0.14"
tokio = { version = "1", features = ["process", "signal"] }
tokio = { version = "1", features = ["process", "signal", "macros"] }
tokio-stream = { version = "0.1.6", features = ["sync"] }
url = "2.1.1"
walkdir = "2.3.1"
Expand Down
3 changes: 1 addition & 2 deletions agent/provider/src/signal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub(crate) type Signal = &'static str;

use tokio::signal::windows::CtrlBreak;
use tokio::task::JoinHandle;
use tokio::{
select,
Expand All @@ -13,7 +12,7 @@ use tokio::{
#[cfg(target_family = "unix")]
use tokio::signal::unix;
#[cfg(target_family = "windows")]
use tokio::signal::windows;
use tokio::signal::{windows, windows::CtrlBreak};

pub struct SignalMonitor {
stop_tx: Sender<Signal>,
Expand Down
4 changes: 2 additions & 2 deletions utils/process/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use {
use {
winapi::um::handleapi::CloseHandle,
winapi::um::processthreadsapi::OpenProcess,
winapi::um::wincon::{GenerateConsoleCtrlEvent, CTRL_C_EVENT},
winapi::um::wincon::{GenerateConsoleCtrlEvent, CTRL_BREAK_EVENT},
winapi::um::winnt::{PROCESS_QUERY_INFORMATION, PROCESS_TERMINATE, SYNCHRONIZE},
};

Expand Down Expand Up @@ -143,7 +143,7 @@ impl ProcessHandle {
));
}

let event_result = GenerateConsoleCtrlEvent(CTRL_C_EVENT, process_pid);
let event_result = GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, process_pid);

if event_result == 0 {
return Err(anyhow!(
Expand Down

0 comments on commit cfb790e

Please sign in to comment.