38 |
|
in the process that calls ExitProcess. |
39 |
|
As presented by Andrew Tucker in Windows Developer Magazine. |
40 |
|
*/ |
41 |
– |
#ifndef OBSOLETE_WINDOWS /* won't work on Win 9X/ME/CE. */ |
41 |
|
BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitCode) |
42 |
|
{ |
43 |
|
DWORD dwTID, dwCode, dwErr = 0; |
77 |
|
if ( !bSuccess ) SetLastError(dwErr); |
78 |
|
return bSuccess; |
79 |
|
} |
81 |
– |
#endif |
80 |
|
|
81 |
|
|
82 |
|
static int |
298 |
|
hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid); |
299 |
|
/* it looks like we want to ignore errors here */ |
300 |
|
if(hProc != NULL) { |
303 |
– |
#ifdef OBSOLETE_WINDOWS |
304 |
– |
#define KILL_TIMEOUT 10 * 1000 /* milliseconds */ |
305 |
– |
/* it might have some windows open... */ |
306 |
– |
EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM)pid); |
307 |
– |
if(WaitForSingleObject(hProc, KILL_TIMEOUT)!=WAIT_OBJECT_0) { |
308 |
– |
/* No way to avoid dangling DLLs here. */ |
309 |
– |
TerminateProcess(hProc, 0); |
310 |
– |
} |
311 |
– |
#else |
301 |
|
SafeTerminateProcess(hProc, 0); |
313 |
– |
#endif |
314 |
– |
/* WaitForSingleObject(hProc, 0); */ |
315 |
– |
/* not much use to wait on Windows */ |
302 |
|
CloseHandle(hProc); |
303 |
|
} |
304 |
|
return 0; /* XXX we need to figure out more here... */ |
317 |
|
pd[i].running = 0; |
318 |
|
if(ocres != 0 || icres != 0) { |
319 |
|
/* something went wrong: enforce infanticide */ |
320 |
< |
/* other than that, it looks like we want to ignore errors here */ |
320 |
> |
/* other than that, it looks like we want to ignore errors */ |
321 |
|
win_kill(pd[i].pid, 0); |
322 |
|
} |
323 |
|
} |