From 6ff703e48c0f4c0897faf4bb07ddd541d7171e7e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Wed, 18 Apr 2018 09:51:52 +0200 Subject: [PATCH] fixup! mingw: kill unterminated child processes on signals This reverts the change where we tried to make sure that child processes are killed upon exit of the git.exe process. This change was misguided: it wanted to pretend that each process was responsible to signal its child processes upon receiving a signal. But it is the responsibility of the syscall `signal()` (or in the case of Windows, either MSYS2's signal() or whoever wanted to terminate the git.exe process) to take care of the child processes. We just changed the MSYS2 runtime accordingly, in the hope that this addresses the Ctrl+C problems (stale .git/index.lock files, runaway git-remote-https when interrupting a clone, killed pager when hitting Ctrl+C in `git log`, interrupting node.js processes that listen to SIGINT, C# programs installing a ConsoleCtrlHandler, etc) once and for all. This commit is part of the fix, as pressing Ctrl+C while `git log` is running would kill the pager otherwise (it is a child process of git.exe after all). Signed-off-by: Johannes Schindelin --- compat/mingw.c | 46 +--------------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 0b86861a96..df4e2d8957 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1528,39 +1528,6 @@ struct pinfo_t { static struct pinfo_t *pinfo = NULL; CRITICAL_SECTION pinfo_cs; -#ifndef SIGRTMAX -#define SIGRTMAX 63 -#endif - -static void kill_child_processes_on_signal(void) -{ - DWORD status; - - /* - * Only continue if the process was terminated by a signal, as - * indicated by the exit status (128 + sig_no). - * - * As we are running in an atexit() handler, the exit code has been - * set at this stage by the ExitProcess() function already. - */ - if (!GetExitCodeProcess(GetCurrentProcess(), &status) || - status <= 128 || status > 128 + SIGRTMAX) - return; - - EnterCriticalSection(&pinfo_cs); - - while (pinfo) { - struct pinfo_t *info = pinfo; - pinfo = pinfo->next; - if (exit_process(info->proc, status)) - /* the handle is still valid in case of error */ - CloseHandle(info->proc); - free(info); - } - - LeaveCriticalSection(&pinfo_cs); -} - static int is_msys2_sh(const char *cmd) { if (cmd && !strcmp(cmd, "sh")) { @@ -1593,7 +1560,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen const char *dir, const char *prepend_cmd, int fhin, int fhout, int fherr) { - static int atexit_handler_initialized, restrict_handle_inheritance = 1; + static int restrict_handle_inheritance = 1; STARTUPINFOEXW si; PROCESS_INFORMATION pi; LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL; @@ -1609,17 +1576,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen const char *(*quote_arg)(const char *arg) = is_msys2_sh(*argv) ? quote_arg_msys2 : quote_arg_msvc; - if (!atexit_handler_initialized) { - atexit_handler_initialized = 1; - /* - * On Windows, there is no POSIX signaling. Instead, we inject - * a thread calling ExitProcess(128 + sig_no); and that calls - * the *atexit* handlers. Catch this condition and kill child - * processes with the same signal. - */ - atexit(kill_child_processes_on_signal); - } - do_unset_environment_variables(); /* Determine whether or not we are associated to a console */