@@ -17,6 +17,7 @@ details. */
17
17
#include < cygwin/version.h>
18
18
#include < getopt.h>
19
19
#include < limits.h>
20
+ #include < cygwin/exit_process.h>
20
21
21
22
static char *prog_name;
22
23
@@ -171,10 +172,28 @@ forcekill (int pid, int sig, int wait)
171
172
return ;
172
173
}
173
174
if (!wait || WaitForSingleObject (h, 200 ) != WAIT_OBJECT_0)
174
- if (sig && !TerminateProcess (h, sig << 8 )
175
- && WaitForSingleObject (h, 200 ) != WAIT_OBJECT_0)
176
- fprintf (stderr, " %s: couldn't kill pid %u, %u\n " ,
175
+ {
176
+ if (sig == SIGINT || sig == SIGTERM)
177
+ {
178
+ HANDLE cur = GetCurrentProcess (), h2;
179
+ /* duplicate handle with access rights required for exit_process() */
180
+ if (DuplicateHandle (cur, h, cur, &h2, PROCESS_CREATE_THREAD |
181
+ PROCESS_QUERY_INFORMATION |
182
+ PROCESS_VM_OPERATION |
183
+ PROCESS_VM_WRITE | PROCESS_VM_READ |
184
+ PROCESS_TERMINATE, FALSE , 0 ))
185
+ {
186
+ exit_process (h2, 128 + sig);
187
+ CloseHandle (h2);
188
+ }
189
+ else
190
+ terminate_process_tree (h, 128 + sig);
191
+ }
192
+ else if (sig && !TerminateProcess (h, sig << 8 )
193
+ && WaitForSingleObject (h, 200 ) != WAIT_OBJECT_0)
194
+ fprintf (stderr, " %s: couldn't kill pid %u, %u\n " ,
177
195
prog_name, (unsigned ) dwpid, (unsigned int ) GetLastError ());
196
+ }
178
197
CloseHandle (h);
179
198
}
180
199
0 commit comments