Skip to content

Commit 1c90995

Browse files
committed
mingw: really handle SIGINT
Previously, we did not install any handler for Ctrl+C, but now we really want to because the MSYS2 runtime learned the trick to call the ConsoleCtrlHandler when Ctrl+C was pressed. With this, hitting Ctrl+C while `git log` is running will only terminate the Git process, but not the pager. This finally matches the behavior on Linux and on macOS. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 4acc1fc commit 1c90995

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 WINAPI 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)