Skip to content

Commit 11b28be

Browse files
committed
Merge branch 'ctrl-c'
This is part two of the Ctrl+C story, where part one is git-for-windows/MSYS2-packages@f4fda0f30aa. Part one took care of extending the signal handling in the MSYS2 runtime such that non-MSYS2 processes "receive" a SIGINT by injecting a remote thread that runs kernel32!CtrlRoutine as if GenerateConsoleCtrlHandler() had been called (but in contrast to the latter, only one process is targeted at a time, not every process attached to the same Console) into the process that needs to be interrupted as well as into all of the spawned child processes. Part two now takes care of removing the misguided "kill all spawned children" atexit() handler, and it also installs a ConsoleCtrl handler to run Git's SIGINT handlers, such as the one waiting for the pager to exit. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 parents 889a26b + 6ea5391 commit 11b28be

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

compat/mingw.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3374,6 +3374,14 @@ static void adjust_symlink_flags(void)
33743374

33753375
}
33763376

3377+
static BOOL WINAPI handle_ctrl_c(DWORD ctrl_type)
3378+
{
3379+
if (ctrl_type != CTRL_C_EVENT)
3380+
return FALSE; /* we did not handle this */
3381+
mingw_raise(SIGINT);
3382+
return TRUE; /* we did handle this */
3383+
}
3384+
33773385
#if defined(_MSC_VER)
33783386

33793387
#ifdef _DEBUG
@@ -3412,6 +3420,8 @@ int msc_startup(int argc, wchar_t **w_argv, wchar_t **w_env)
34123420
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
34133421
#endif
34143422

3423+
SetConsoleCtrlHandler(handle_ctrl_c, TRUE);
3424+
34153425
fsync_object_files = 1;
34163426
maybe_redirect_std_handles();
34173427
adjust_symlink_flags();
@@ -3480,6 +3490,8 @@ void mingw_startup(void)
34803490
wchar_t **wenv, **wargv;
34813491
_startupinfo si;
34823492

3493+
SetConsoleCtrlHandler(handle_ctrl_c, TRUE);
3494+
34833495
fsync_object_files = 1;
34843496
maybe_redirect_std_handles();
34853497
adjust_symlink_flags();

0 commit comments

Comments
 (0)