Files
MSYS2-packages/msys2-runtime/0041-kill-kill-Win32-processes-more-gently.patch
Johannes Schindelin 18472f9dc3 msys2-runtime: handle Ctrl+C with MINGW executables
The idea is that we handle Ctrl+C not by terminating the processes
(which would reflect `kill -KILL`, not `kill -INT`) but by imitating
what Windows does in a CMD window: we inject a remote thread that runs
the `CtrlRoutine` function. This lets the `atexit()` handlers and the
ConsoleCtrlEvent handlers do their job.

This commit brings the goodness from
https://github.com/msys2/msys2-runtime/pull/31 over into MSYS2-packages,
which cherry-picked and edited the patches from Git for Windows.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2021-06-18 13:03:48 +02:00

55 lines
1.7 KiB
Diff

From d8b7c36469cc38280e07b32e552b763841a2b134 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Fri, 20 Mar 2015 10:01:50 +0000
Subject: [PATCH 41/N] kill: kill Win32 processes more gently
This change is the equivalent to the change to the Ctrl+C handling we
just made.
Co-authored-by: Naveen M K <naveen@syrusdark.website>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
winsup/utils/kill.cc | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc
index d0fb547..e55df49 100644
--- a/winsup/utils/kill.cc
+++ b/winsup/utils/kill.cc
@@ -17,6 +17,7 @@ details. */
#include <cygwin/version.h>
#include <getopt.h>
#include <limits.h>
+#include <cygwin/exit_process.h>
static char *prog_name;
@@ -186,10 +187,20 @@ forcekill (pid_t pid, DWORD winpid, int sig, int wait)
return;
}
if (!wait || WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
- if (sig && !TerminateProcess (h, sig << 8)
- && WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
- fprintf (stderr, "%s: couldn't kill pid %u, %u\n",
- prog_name, (unsigned int) dwpid, (unsigned int) GetLastError ());
+ {
+ HANDLE cur = GetCurrentProcess (), h2;
+ /* duplicate handle with access rights required for exit_process_tree() */
+ if (DuplicateHandle (cur, h, cur, &h2, PROCESS_CREATE_THREAD |
+ PROCESS_QUERY_INFORMATION |
+ PROCESS_VM_OPERATION |
+ PROCESS_VM_WRITE | PROCESS_VM_READ |
+ PROCESS_TERMINATE, FALSE, 0))
+ {
+ CloseHandle(h);
+ h = h2;
+ }
+ exit_process_tree (h2, 128 + sig);
+ }
CloseHandle (h);
}
--
2.31.1