Skip to content

Commit ac09de9

Browse files
author
Git for Windows Build Agent
committed
msys2-runtime: update to v2.9.0 (7)
Signed-off-by: Git for Windows Build Agent <[email protected]>
1 parent a851113 commit ac09de9

3 files changed

+294
-3
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
From 7ac70fa13cc094ea64b920fc9f4b2824193a4e73 Mon Sep 17 00:00:00 2001
2+
From: Johannes Schindelin <[email protected]>
3+
Date: Fri, 12 Jan 2018 20:54:06 +0100
4+
Subject: [PATCH 60/N] squash! Try to kill Win32 processes gently upon Ctrl+C
5+
6+
Let's redo a bit more of this. We will need to squash this into the
7+
original Ctrl+C patch during the next merging-rebase.
8+
9+
Signed-off-by: Johannes Schindelin <[email protected]>
10+
---
11+
winsup/cygwin/include/cygwin/exit_process.h | 3 ++-
12+
winsup/utils/kill.cc | 31 ++++++++++++-----------------
13+
2 files changed, 15 insertions(+), 19 deletions(-)
14+
15+
diff --git a/winsup/cygwin/include/cygwin/exit_process.h b/winsup/cygwin/include/cygwin/exit_process.h
16+
index 11d546a..01c0a47 100644
17+
--- a/winsup/cygwin/include/cygwin/exit_process.h
18+
+++ b/winsup/cygwin/include/cygwin/exit_process.h
19+
@@ -176,7 +176,8 @@ exit_process(HANDLE process, int exit_code)
20+
21+
if (GetExitCodeProcess (process, &code) && code == STILL_ACTIVE)
22+
{
23+
- if (process_architecture_matches_current(process) && (exit_code == SIGINT || exit_code == SIGTERM))
24+
+ int signal = exit_code & 0x7f;
25+
+ if (process_architecture_matches_current(process) && (signal == SIGINT || signal == SIGTERM))
26+
return terminate_process_tree (process, exit_code, terminate_process_with_remote_thread);
27+
28+
return terminate_process_tree (process, exit_code, terminate_process);
29+
diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc
30+
index 05a282a..a771df6 100644
31+
--- a/winsup/utils/kill.cc
32+
+++ b/winsup/utils/kill.cc
33+
@@ -173,24 +173,19 @@ forcekill (int pid, int sig, int wait)
34+
}
35+
if (!wait || WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
36+
{
37+
- if (sig == SIGINT || sig == SIGTERM)
38+
- {
39+
- HANDLE cur = GetCurrentProcess (), h2;
40+
- /* duplicate handle with access rights required for exit_process() */
41+
- if (DuplicateHandle (cur, h, cur, &h2, PROCESS_CREATE_THREAD |
42+
- PROCESS_QUERY_INFORMATION |
43+
- PROCESS_VM_OPERATION |
44+
- PROCESS_VM_WRITE | PROCESS_VM_READ |
45+
- PROCESS_TERMINATE, FALSE, 0))
46+
- {
47+
- exit_process (h2, 128 + sig);
48+
- CloseHandle (h2);
49+
- }
50+
- else
51+
- exit_process (h, 128 + sig);
52+
- }
53+
- else if (sig && !TerminateProcess (h, sig << 8)
54+
- && WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
55+
+ HANDLE cur = GetCurrentProcess (), h2;
56+
+ /* duplicate handle with access rights required for exit_process() */
57+
+ if (DuplicateHandle (cur, h, cur, &h2, PROCESS_CREATE_THREAD |
58+
+ PROCESS_QUERY_INFORMATION |
59+
+ PROCESS_VM_OPERATION |
60+
+ PROCESS_VM_WRITE | PROCESS_VM_READ |
61+
+ PROCESS_TERMINATE, FALSE, 0))
62+
+ {
63+
+ h = h2;
64+
+ CloseHandle (h);
65+
+ }
66+
+ exit_process (h, 128 + sig);
67+
+ if (WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
68+
fprintf (stderr, "%s: couldn't kill pid %u, %u\n",
69+
prog_name, (unsigned) dwpid, (unsigned int) GetLastError ());
70+
}
71+
--
72+
2.9.0
73+
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
From c967bd8e37af7fa86f8ed1ded2625071612b808a Mon Sep 17 00:00:00 2001
2+
From: Johannes Schindelin <[email protected]>
3+
Date: Fri, 12 Jan 2018 20:54:06 +0100
4+
Subject: [PATCH 61/N] squash! Try to kill Win32 processes gently upon Ctrl+C
5+
6+
Let's redo this. We will need to squash this into the original Ctrl+C
7+
patch during the next merging-rebase.
8+
9+
Handle SIGINT/SIGTERM specifically via Ctrl events
10+
11+
This assumes that we want to send the signal to a console process. It
12+
would not make sense in any other case, anyway, to try to emulate a
13+
Ctrl+C: where there is no Console, there are no keystrokes.
14+
15+
[expand explanation here]
16+
17+
Signed-off-by: Johannes Schindelin <[email protected]>
18+
---
19+
winsup/cygwin/exceptions.cc | 2 +-
20+
winsup/cygwin/include/cygwin/exit_process.h | 120 ++++++++++++----------------
21+
winsup/utils/kill.cc | 7 +-
22+
3 files changed, 53 insertions(+), 76 deletions(-)
23+
24+
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
25+
index 7b4a163..8afcf00 100644
26+
--- a/winsup/cygwin/exceptions.cc
27+
+++ b/winsup/cygwin/exceptions.cc
28+
@@ -1561,7 +1561,7 @@ dosig:
29+
goto done;
30+
default:
31+
sigproc_printf ("terminating captive process");
32+
- exit_process (ch_spawn, 128 + (sigExeced = si.si_signo));
33+
+ exit_process (ch_spawn, 128 + (sigExeced = si.si_signo), 0);
34+
break;
35+
}
36+
}
37+
diff --git a/winsup/cygwin/include/cygwin/exit_process.h b/winsup/cygwin/include/cygwin/exit_process.h
38+
index 01c0a47..6783950 100644
39+
--- a/winsup/cygwin/include/cygwin/exit_process.h
40+
+++ b/winsup/cygwin/include/cygwin/exit_process.h
41+
@@ -5,8 +5,8 @@
42+
* This file contains functions to terminate a Win32 process, as gently as
43+
* possible.
44+
*
45+
- * At first, we will attempt to inject a thread that calls ExitProcess(). If
46+
- * that fails, we will fall back to terminating the entire process tree.
47+
+ * If appropriate, we will attempt to generate a console Ctrl event.
48+
+ * Otherwise we will fall back to terminating the entire process tree.
49+
*
50+
* As we do not want to export this function in the MSYS2 runtime, these
51+
* functions are marked as file-local.
52+
@@ -14,36 +14,6 @@
53+
54+
#include <tlhelp32.h>
55+
56+
-static int
57+
-terminate_process_with_remote_thread(HANDLE process, int exit_code)
58+
-{
59+
- static LPTHREAD_START_ROUTINE exit_process_address;
60+
- if (!exit_process_address)
61+
- {
62+
- HINSTANCE kernel32 = GetModuleHandle ("kernel32");
63+
- exit_process_address = (LPTHREAD_START_ROUTINE)
64+
- GetProcAddress (kernel32, "ExitProcess");
65+
- }
66+
- DWORD thread_id;
67+
- HANDLE thread = !exit_process_address ? NULL :
68+
- CreateRemoteThread (process, NULL, 0, exit_process_address,
69+
- (PVOID)exit_code, 0, &thread_id);
70+
-
71+
- if (thread)
72+
- {
73+
- CloseHandle (thread);
74+
- /*
75+
- * Wait 10 seconds (arbitrary constant) for the process to
76+
- * finish; After that grace period, fall back to terminating
77+
- * non-gently.
78+
- */
79+
- if (WaitForSingleObject (process, 10000) == WAIT_OBJECT_0)
80+
- return 0;
81+
- }
82+
-
83+
- return -1;
84+
-}
85+
-
86+
/**
87+
* Terminates the process corresponding to the process ID
88+
*
89+
@@ -133,52 +103,62 @@ terminate_process_tree(HANDLE main_process, int exit_code, int (*terminate)(HAND
90+
}
91+
92+
/**
93+
- * Determine whether a process runs in the same architecture as the current
94+
- * one. That test is required before we assume that GetProcAddress() returns
95+
- * a valid address *for the target process*.
96+
- */
97+
-static inline bool
98+
-process_architecture_matches_current(HANDLE process)
99+
-{
100+
- static BOOL current_is_wow = -1;
101+
- BOOL is_wow;
102+
-
103+
- if (current_is_wow == -1 &&
104+
- !IsWow64Process (GetCurrentProcess (), &current_is_wow))
105+
- current_is_wow = -2;
106+
- if (current_is_wow == -2)
107+
- return false; /* could not determine current process' WoW-ness */
108+
- if (!IsWow64Process (process, &is_wow))
109+
- return false; /* cannot determine */
110+
- return is_wow == current_is_wow;
111+
-}
112+
-
113+
-/**
114+
- * Inject a thread into the given process that runs ExitProcess().
115+
- *
116+
- * Note: as kernel32.dll is loaded before any process, the other process and
117+
- * this process will have ExitProcess() at the same address.
118+
- *
119+
- * This function expects the process handle to have the access rights for
120+
- * CreateRemoteThread(): PROCESS_CREATE_THREAD, PROCESS_QUERY_INFORMATION,
121+
- * PROCESS_VM_OPERATION, PROCESS_VM_WRITE, and PROCESS_VM_READ.
122+
- *
123+
- * The idea comes from the Dr Dobb's article "A Safer Alternative to
124+
- * TerminateProcess()" by Andrew Tucker (July 1, 1999),
125+
- * http://www.drdobbs.com/a-safer-alternative-to-terminateprocess/184416547
126+
- *
127+
- * If this method fails, we fall back to running terminate_process_tree().
128+
+ * For SIGINT/SIGTERM, call GenerateConsoleCtrlEven(). Otherwise fall back to
129+
+ * running terminate_process_tree().
130+
*/
131+
static int
132+
-exit_process(HANDLE process, int exit_code)
133+
+exit_process(HANDLE process, int exit_code, int okay_to_kill_this_process)
134+
{
135+
DWORD code;
136+
137+
if (GetExitCodeProcess (process, &code) && code == STILL_ACTIVE)
138+
{
139+
int signal = exit_code & 0x7f;
140+
- if (process_architecture_matches_current(process) && (signal == SIGINT || signal == SIGTERM))
141+
- return terminate_process_tree (process, exit_code, terminate_process_with_remote_thread);
142+
+ if (signal == SIGINT || signal == SIGTERM)
143+
+ {
144+
+#ifndef __INSIDE_CYGWIN__
145+
+ if (!okay_to_kill_this_process)
146+
+ return -1;
147+
+ FreeConsole();
148+
+ if (!AttachConsole(GetProcessId(process)))
149+
+ return -1;
150+
+ if (GenerateConsoleCtrlEvent(signal == SIGINT ? CTRL_C_EVENT : CTRL_BREAK_EVENT, 0))
151+
+ return 0;
152+
+#else
153+
+ path_conv helper ("/bin/kill.exe");
154+
+ if (helper.exists ())
155+
+ {
156+
+ STARTUPINFOW si = {};
157+
+ PROCESS_INFORMATION pi;
158+
+ size_t len = helper.get_wide_win32_path_len ();
159+
+ WCHAR cmd[len + (2 * strlen (" -f -32 0xffffffff")) + 1];
160+
+ WCHAR title[] = L"kill";
161+
+
162+
+ helper.get_wide_win32_path (cmd);
163+
+ __small_swprintf (cmd + len, L" -f -%d %d", signal, (int)GetProcessId(ch_spawn));
164+
+
165+
+ si.cb = sizeof (si);
166+
+ si.dwFlags = STARTF_USESHOWWINDOW;
167+
+ si.wShowWindow = SW_HIDE;
168+
+ si.lpTitle = title;
169+
+
170+
+ /* Create a new hidden process. Use the two event handles as
171+
+ argv[1] and argv[2]. */
172+
+ BOOL x = CreateProcessW (NULL, cmd, &sec_none_nih, &sec_none_nih,
173+
+ true, CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
174+
+ if (x)
175+
+ {
176+
+ CloseHandle (pi.hThread);
177+
+ if (WaitForSingleObject (pi.hProcess, 10000) == WAIT_OBJECT_0)
178+
+ {
179+
+ CloseHandle (pi.hProcess);
180+
+ return 0;
181+
+ }
182+
+ CloseHandle (pi.hProcess);
183+
+ }
184+
+ }
185+
+#endif
186+
+ }
187+
188+
return terminate_process_tree (process, exit_code, terminate_process);
189+
}
190+
diff --git a/winsup/utils/kill.cc b/winsup/utils/kill.cc
191+
index a771df6..911eedb 100644
192+
--- a/winsup/utils/kill.cc
193+
+++ b/winsup/utils/kill.cc
194+
@@ -181,13 +181,10 @@ forcekill (int pid, int sig, int wait)
195+
PROCESS_VM_WRITE | PROCESS_VM_READ |
196+
PROCESS_TERMINATE, FALSE, 0))
197+
{
198+
+ CloseHandle(h);
199+
h = h2;
200+
- CloseHandle (h);
201+
}
202+
- exit_process (h, 128 + sig);
203+
- if (WaitForSingleObject (h, 200) != WAIT_OBJECT_0)
204+
- fprintf (stderr, "%s: couldn't kill pid %u, %u\n",
205+
- prog_name, (unsigned) dwpid, (unsigned int) GetLastError ());
206+
+ exit_process (h2, 128 + sig, 1);
207+
}
208+
CloseHandle (h);
209+
}
210+
--
211+
2.9.0
212+

msys2-runtime/PKGBUILD

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
pkgbase=msys2-runtime
55
pkgname=('msys2-runtime' 'msys2-runtime-devel')
66
pkgver=2.9.0
7-
pkgrel=6
7+
pkgrel=7
88
pkgdesc="Cygwin POSIX emulation engine"
99
arch=('i686' 'x86_64')
1010
url="https://www.cygwin.com/"
@@ -83,7 +83,9 @@ source=('msys2-runtime'::git://sourceware.org/git/newlib-cygwin.git#tag=cygwin-$
8383
0056-fixup-Avoid-comparing-this-to-NULL.patch
8484
0057-Generate-a-.pdb-file-instead-of-a-.dbg-file.patch
8585
0058-exit_process.h-fix-handling-of-SIGINT-and-SIGTERM.patch
86-
0059-fixup-exit_process.h-fix-handling-of-SIGINT-and-SIGT.patch)
86+
0059-fixup-exit_process.h-fix-handling-of-SIGINT-and-SIGT.patch
87+
0060-squash-Try-to-kill-Win32-processes-gently-upon-Ctrl-.patch
88+
0061-squash-Try-to-kill-Win32-processes-gently-upon-Ctrl-.patch)
8789
sha256sums=('SKIP'
8890
'412a414e00ed0976611b42dc1dcb2ac29741200b40d42ae281a5c74ec09844d4'
8991
'580634b80de13b1730b648042d955cf0db40af97a6967602f4634c3034c06a9c'
@@ -143,7 +145,9 @@ sha256sums=('SKIP'
143145
'bb7c2d09d76fe3605038b9b5180f8ae0f43e8572c977370366bf74a7b1d7984f'
144146
'e2af87d99d123ee03ecf349484f929d9ce317517a7c11391ed10b6c541ad3463'
145147
'c498917c9764354a23ddf8f977b962808d6da4eb643a5e0bb9b8f2641f0bfd21'
146-
'd8662a56b162f1bb12039464f7447c58f374ba8e8b812451661c5f9be3ef1155')
148+
'd8662a56b162f1bb12039464f7447c58f374ba8e8b812451661c5f9be3ef1155'
149+
'9c8f81efaf46ffb1b648a1997d8158d61bd09decb47e125f65d0fe5acacee1aa'
150+
'fd032542147cde60a3f02ff508f63ce01392e8084ef6900639db5d22c935b673')
147151
prepare() {
148152
cd "${srcdir}"/msys2-runtime
149153
git am --committer-date-is-author-date "${srcdir}"/0001-Add-MSYS-triplets.patch
@@ -205,6 +209,8 @@ prepare() {
205209
git am --committer-date-is-author-date "${srcdir}"/0057-Generate-a-.pdb-file-instead-of-a-.dbg-file.patch
206210
git am --committer-date-is-author-date "${srcdir}"/0058-exit_process.h-fix-handling-of-SIGINT-and-SIGTERM.patch
207211
git am --committer-date-is-author-date "${srcdir}"/0059-fixup-exit_process.h-fix-handling-of-SIGINT-and-SIGT.patch
212+
git am --committer-date-is-author-date "${srcdir}"/0060-squash-Try-to-kill-Win32-processes-gently-upon-Ctrl-.patch
213+
git am --committer-date-is-author-date "${srcdir}"/0061-squash-Try-to-kill-Win32-processes-gently-upon-Ctrl-.patch
208214
}
209215

210216
build() {

0 commit comments

Comments
 (0)