21 |
|
#include "rtprocess.h" |
22 |
|
|
23 |
|
|
24 |
< |
/* Looks like some Windows versions use negative PIDs. |
25 |
< |
Let's just hope they either make them *all* negative, or none. */ |
26 |
< |
static int system_uses_negative_pids = 0; |
24 |
> |
int |
25 |
> |
win_nice(int inc) /* simple nice(2) replacement for Windows */ |
26 |
> |
{ |
27 |
> |
/* We don't have much granularity available: IDLE_PRIORITY_CLASS |
28 |
> |
will run whenever no other higher priority process is running */ |
29 |
> |
if (inc > 0) { |
30 |
> |
return (int)!SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS); |
31 |
> |
} |
32 |
> |
return 0; |
33 |
> |
} |
34 |
|
|
35 |
|
|
36 |
|
/* |
167 |
|
CloseHandle(hFromChildWrite); hFromChildWrite = NULL; |
168 |
|
CloseHandle(hToChildRead); hToChildRead = NULL; |
169 |
|
/* get the file descriptors */ |
170 |
< |
proc->r = _open_osfhandle((long)hRead, _O_RDONLY); |
171 |
< |
proc->w = _open_osfhandle((long)hWrite, _O_APPEND); |
170 |
> |
proc->r = _open_osfhandle((long)hRead, _O_RDONLY|_O_BINARY); |
171 |
> |
proc->w = _open_osfhandle((long)hWrite, _O_APPEND|_O_BINARY); |
172 |
|
proc->pid = PInfo.dwProcessId; |
173 |
|
proc->running = 1; |
174 |
|
CloseHandle(hCurProc); |
185 |
|
if(hWrite) CloseHandle(hWrite); |
186 |
|
if(hCurProc) CloseHandle(hCurProc); |
187 |
|
proc->running = 0; |
188 |
< |
return 0; |
188 |
> |
return -1; |
189 |
|
/* There... Are we happy now? */ |
190 |
|
} |
191 |
|
|
279 |
|
char *cmdpath; |
280 |
|
char *cmdstr; |
281 |
|
|
282 |
+ |
if (av == NULL || av[0] == NULL) { |
283 |
+ |
fputs("Illegal call to open_process()!\n", stderr); |
284 |
+ |
return -1; |
285 |
+ |
} |
286 |
+ |
proc->pid = 0; |
287 |
|
proc->running = 0; |
288 |
+ |
if (av == NULL) { return -1; } |
289 |
|
cmdpath = getpath(av[0], getenv("PATH"), X_OK); |
290 |
< |
cmdstr = quoted_cmdline(cmdpath, av); |
290 |
> |
cmdstr = quoted_cmdline(cmdpath, av+1); |
291 |
|
if (cmdstr == NULL) { return 0; } |
292 |
|
return start_process(proc, cmdstr); |
293 |
|
} |
294 |
|
|
295 |
|
|
296 |
< |
int |
297 |
< |
close_process(SUBPROC *proc) { |
285 |
< |
int icres, ocres; |
286 |
< |
DWORD pid; |
296 |
> |
int win_kill(RT_PID pid, int sig) /* we ignore sig... */ |
297 |
> |
{ |
298 |
|
HANDLE hProc; |
299 |
|
|
300 |
< |
ocres = close(proc->w); |
301 |
< |
icres = close(proc->r); |
302 |
< |
pid = proc->pid; |
292 |
< |
if(ocres != 0 || icres != 0) { |
293 |
< |
hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid); |
294 |
< |
/* something went wrong: enforce infanticide */ |
295 |
< |
/* other than that, it looks like we want to ignore errors here */ |
296 |
< |
if (proc->running) { |
297 |
< |
if(hProc != NULL) { |
300 |
> |
hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid); |
301 |
> |
/* it looks like we want to ignore errors here */ |
302 |
> |
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 |
< |
} |
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 |
312 |
< |
SafeTerminateProcess(hProc, 0); |
312 |
> |
SafeTerminateProcess(hProc, 0); |
313 |
|
#endif |
314 |
< |
/* WaitForSingleObject(hProc, 0); */ |
315 |
< |
/* not much use to wait on Windows */ |
316 |
< |
CloseHandle(hProc); |
314 |
> |
/* WaitForSingleObject(hProc, 0); */ |
315 |
> |
/* not much use to wait on Windows */ |
316 |
> |
CloseHandle(hProc); |
317 |
> |
} |
318 |
> |
return 0; /* XXX we need to figure out more here... */ |
319 |
> |
} |
320 |
> |
|
321 |
> |
|
322 |
> |
int |
323 |
> |
close_processes(SUBPROC pd[], int nproc) { |
324 |
> |
int i, icres, ocres; |
325 |
> |
DWORD pid; |
326 |
> |
|
327 |
> |
for (i = 0; i < nproc; i++) { |
328 |
> |
if (pid[i].running) { |
329 |
> |
ocres = close(pd[i].w); |
330 |
> |
icres = close(pd[i].r); |
331 |
> |
pd[i].running = 0; |
332 |
> |
if(ocres != 0 || icres != 0) { |
333 |
> |
/* something went wrong: enforce infanticide */ |
334 |
> |
/* other than that, it looks like we want to ignore errors here */ |
335 |
> |
win_kill(pd[i].pid, 0); |
336 |
|
} |
337 |
|
} |
338 |
+ |
pd[i].pid = 0; |
339 |
|
} |
315 |
– |
proc->running = 0; |
340 |
|
return 0; /* XXX we need to figure out more here... */ |
341 |
|
} |
342 |
|
|