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 |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
< |
static int /* copied size or -1 on error */ |
191 |
> |
static size_t /* copied size or -1 on error */ |
192 |
|
wordncopy( /* copy (quoted) src to dest. */ |
193 |
|
|
194 |
|
char * dest, |
195 |
|
char * src, |
196 |
< |
int dlen, |
196 |
> |
size_t dlen, |
197 |
|
int insert_space, /* prepend a space */ |
198 |
|
int force_dq /* turn 'src' into "dest" (for Win command line) */ |
199 |
|
) |
200 |
|
{ |
201 |
< |
int slen; |
202 |
< |
int pos = 0; |
201 |
> |
size_t slen; |
202 |
> |
size_t pos = 0; |
203 |
|
|
204 |
|
slen = strlen(src); |
205 |
|
if (insert_space) { |
243 |
|
) |
244 |
|
{ |
245 |
|
static char *cmdstr; |
246 |
< |
static int clen; |
246 |
> |
static size_t clen; |
247 |
|
char *newcs; |
248 |
< |
int newlen, pos, res, i; |
248 |
> |
size_t newlen, pos, i, res; |
249 |
|
|
250 |
|
newlen = strlen(cmdpath) + 3; /* allow two quotes plus the final \0 */ |
251 |
|
for (i = 0; sl[i] != NULL; i++) { |
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... */ |
311 |
|
DWORD pid; |
312 |
|
|
313 |
|
for (i = 0; i < nproc; i++) { |
314 |
< |
if (pid[i].running) { |
314 |
> |
if (pd[i].running) { |
315 |
|
ocres = close(pd[i].w); |
316 |
|
icres = close(pd[i].r); |
317 |
|
pd[i].running = 0; |
318 |
< |
} |
319 |
< |
if(ocres != 0 || icres != 0) { |
320 |
< |
/* something went wrong: enforce infanticide */ |
321 |
< |
/* other than that, it looks like we want to ignore errors here */ |
322 |
< |
win_kill(pd[i].pid, 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 */ |
321 |
> |
win_kill(pd[i].pid, 0); |
322 |
> |
} |
323 |
|
} |
324 |
|
pd[i].pid = 0; |
325 |
|
} |