Skip to content

Commit bb29dc4

Browse files
branchseerclaude
andcommitted
Fix incorrect comment: ConPTY sets CTRL_C ignore flag, not Rust runtime
Investigation confirmed Rust std, ctrlc crate, and portable-pty have zero calls to SetConsoleCtrlHandler(NULL, TRUE). The inheritable ignore flag is set by the Windows ConPTY subsystem for spawned processes. The SetConsoleCtrlHandler(None, 0) workaround is still needed — without it the test times out on Windows — but the comment was wrong about the source. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4e48134 commit bb29dc4

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

crates/pty_terminal/tests/terminal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ fn send_ctrl_c_interrupts_process() {
305305
// On macOS/Windows, use ctrlc which works fine (no .init_array/musl issue).
306306
#[cfg(not(target_os = "linux"))]
307307
{
308-
// On Windows, clear the "ignore CTRL_C" flag set by Rust runtime
309-
// so that CTRL_C_EVENT reaches the ctrlc handler.
308+
// On Windows, processes spawned inside a ConPTY inherit an "ignore
309+
// CTRL_C" flag. Clear it so that CTRL_C_EVENT reaches our handler.
310310
#[cfg(windows)]
311311
{
312312
// SAFETY: Declaring correct signature for SetConsoleCtrlHandler from kernel32.

crates/vite_task_bin/src/vtt/exit_on_ctrlc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
/// Sets up a Ctrl+C handler, emits a "ready" milestone, then waits.
44
/// When Ctrl+C is received, prints "ctrl-c received" and exits.
55
pub fn run() -> Result<(), Box<dyn std::error::Error>> {
6-
// On Windows, Rust's runtime sets `SetConsoleCtrlHandler(NULL, TRUE)` which
7-
// ignores CTRL_C_EVENT. This flag is inherited by child processes and takes
8-
// precedence over registered handlers. Clear it before registering ours.
6+
// On Windows, processes spawned inside a ConPTY inherit an "ignore CTRL_C"
7+
// flag (`SetConsoleCtrlHandler(NULL, TRUE)`). This takes precedence over
8+
// registered handlers, so clear it before registering ours.
99
#[cfg(windows)]
1010
{
11-
// SAFETY: Passing (None, FALSE) removes the "ignore CTRL_C" flag.
11+
// SAFETY: Passing (None, FALSE) removes the per-process "ignore CTRL_C" flag.
1212
unsafe extern "system" {
1313
fn SetConsoleCtrlHandler(
1414
handler: Option<unsafe extern "system" fn(u32) -> i32>,
1515
add: i32,
1616
) -> i32;
1717
}
18-
// SAFETY: Clearing the Rust runtime's ignore flag.
18+
// SAFETY: Clearing the inherited ignore flag.
1919
unsafe {
2020
SetConsoleCtrlHandler(None, 0);
2121
}

0 commit comments

Comments
 (0)