Skip to content

Commit 6ea5391

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 <johannes.schindelin@gmx.de>
1 parent 889a26b commit 6ea5391

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)