Skip to content

Commit 6ff703e

Browse files
committed
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 <[email protected]>
1 parent 7e4058d commit 6ff703e

File tree

1 file changed

+1
-45
lines changed

1 file changed

+1
-45
lines changed

compat/mingw.c

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,39 +1528,6 @@ struct pinfo_t {
15281528
static struct pinfo_t *pinfo = NULL;
15291529
CRITICAL_SECTION pinfo_cs;
15301530

1531-
#ifndef SIGRTMAX
1532-
#define SIGRTMAX 63
1533-
#endif
1534-
1535-
static void kill_child_processes_on_signal(void)
1536-
{
1537-
DWORD status;
1538-
1539-
/*
1540-
* Only continue if the process was terminated by a signal, as
1541-
* indicated by the exit status (128 + sig_no).
1542-
*
1543-
* As we are running in an atexit() handler, the exit code has been
1544-
* set at this stage by the ExitProcess() function already.
1545-
*/
1546-
if (!GetExitCodeProcess(GetCurrentProcess(), &status) ||
1547-
status <= 128 || status > 128 + SIGRTMAX)
1548-
return;
1549-
1550-
EnterCriticalSection(&pinfo_cs);
1551-
1552-
while (pinfo) {
1553-
struct pinfo_t *info = pinfo;
1554-
pinfo = pinfo->next;
1555-
if (exit_process(info->proc, status))
1556-
/* the handle is still valid in case of error */
1557-
CloseHandle(info->proc);
1558-
free(info);
1559-
}
1560-
1561-
LeaveCriticalSection(&pinfo_cs);
1562-
}
1563-
15641531
static int is_msys2_sh(const char *cmd)
15651532
{
15661533
if (cmd && !strcmp(cmd, "sh")) {
@@ -1593,7 +1560,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
15931560
const char *dir, const char *prepend_cmd,
15941561
int fhin, int fhout, int fherr)
15951562
{
1596-
static int atexit_handler_initialized, restrict_handle_inheritance = 1;
1563+
static int restrict_handle_inheritance = 1;
15971564
STARTUPINFOEXW si;
15981565
PROCESS_INFORMATION pi;
15991566
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
16091576
const char *(*quote_arg)(const char *arg) =
16101577
is_msys2_sh(*argv) ? quote_arg_msys2 : quote_arg_msvc;
16111578

1612-
if (!atexit_handler_initialized) {
1613-
atexit_handler_initialized = 1;
1614-
/*
1615-
* On Windows, there is no POSIX signaling. Instead, we inject
1616-
* a thread calling ExitProcess(128 + sig_no); and that calls
1617-
* the *atexit* handlers. Catch this condition and kill child
1618-
* processes with the same signal.
1619-
*/
1620-
atexit(kill_child_processes_on_signal);
1621-
}
1622-
16231579
do_unset_environment_variables();
16241580

16251581
/* Determine whether or not we are associated to a console */

0 commit comments

Comments
 (0)