From 1cbdbd74640ad23db005fc09a03a73302c2664f1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 23 Apr 2018 00:24:29 +0200 Subject: [PATCH] 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 --- compat/mingw.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compat/mingw.c b/compat/mingw.c index df4e2d8957..456bf2cd9b 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -3294,6 +3294,14 @@ static void adjust_symlink_flags(void) } +static BOOL handle_ctrl_c(DWORD ctrl_type) +{ + if (ctrl_type != CTRL_C_EVENT) + return FALSE; /* we did not handle this */ + mingw_raise(SIGINT); + return TRUE; /* we did handle this */ +} + #if defined(_MSC_VER) #ifdef _DEBUG @@ -3332,6 +3340,8 @@ int msc_startup(int argc, wchar_t **w_argv, wchar_t **w_env) _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); #endif + SetConsoleCtrlHandler(handle_ctrl_c, TRUE); + fsync_object_files = 1; maybe_redirect_std_handles(); adjust_symlink_flags(); @@ -3400,6 +3410,8 @@ void mingw_startup(void) wchar_t **wenv, **wargv; _startupinfo si; + SetConsoleCtrlHandler(handle_ctrl_c, TRUE); + fsync_object_files = 1; maybe_redirect_std_handles(); adjust_symlink_flags();