Skip to content

Commit 2df74d6

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 <[email protected]>
2 parents 242e248 + b422d11 commit 2df74d6

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
@@ -3337,6 +3337,14 @@ static void adjust_symlink_flags(void)
33373337

33383338
}
33393339

3340+
static BOOL handle_ctrl_c(DWORD ctrl_type)
3341+
{
3342+
if (ctrl_type != CTRL_C_EVENT)
3343+
return FALSE; /* we did not handle this */
3344+
mingw_raise(SIGINT);
3345+
return TRUE; /* we did handle this */
3346+
}
3347+
33403348
#if defined(_MSC_VER)
33413349

33423350
#ifdef _DEBUG
@@ -3375,6 +3383,8 @@ int msc_startup(int argc, wchar_t **w_argv, wchar_t **w_env)
33753383
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
33763384
#endif
33773385

3386+
SetConsoleCtrlHandler(handle_ctrl_c, TRUE);
3387+
33783388
fsync_object_files = 1;
33793389
maybe_redirect_std_handles();
33803390
adjust_symlink_flags();
@@ -3443,6 +3453,8 @@ void mingw_startup(void)
34433453
wchar_t **wenv, **wargv;
34443454
_startupinfo si;
34453455

3456+
SetConsoleCtrlHandler(handle_ctrl_c, TRUE);
3457+
34463458
fsync_object_files = 1;
34473459
maybe_redirect_std_handles();
34483460
adjust_symlink_flags();

0 commit comments

Comments
 (0)