Skip to content

Commit bdbdc48

Browse files
committed
Change from CTRL_C_EVENT to CTRL_BREAK_EVENT on Windows
1 parent e7f2ec1 commit bdbdc48

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,15 @@ mod inner {
6767

6868
#[cfg(windows)]
6969
pub fn interrupt(pid: u32) -> io::Result<()> {
70-
use windows_sys::Win32::System::Console::{CTRL_C_EVENT, GenerateConsoleCtrlEvent};
70+
use windows_sys::Win32::System::Console::{CTRL_BREAK_EVENT, GenerateConsoleCtrlEvent};
7171

72-
// NOTE: This only works if the process is in a new process group
72+
// NOTE: After testing, it seems CTRL_BREAK_EVENT works in all cases (or all the ones I tried).
73+
// CTRL_C_EVENT didn't work when using the `ctrlc` crate, for example, which is my primary use case.
74+
// NOTE 2: This only works if the process is in a new process group. I had mixed results with this,
75+
// so I'm not sure if it's actually required, but in one case it broke Windows CI, so I'm leaving it in.
7376
// SAFETY: This is a standard Windows console function. Any number passed in is memory safe,
7477
// even if it impacts a process the user hadn't intended.
75-
if unsafe { GenerateConsoleCtrlEvent(CTRL_C_EVENT, pid) } != 0 {
78+
if unsafe { GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, pid) } != 0 {
7679
Ok(())
7780
} else {
7881
Err(io::Error::last_os_error())

0 commit comments

Comments
 (0)