16 |
|
#include <io.h> /* _open_osfhandle */ |
17 |
|
#include <fcntl.h> /* _O_XXX */ |
18 |
|
|
19 |
< |
#include "standard.h" |
19 |
> |
#include "rterror.h" |
20 |
> |
#include "rtio.h" |
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 |
|
/* |
278 |
|
{ |
279 |
|
char *cmdpath; |
280 |
|
char *cmdstr; |
273 |
– |
int res; |
281 |
|
|
282 |
|
proc->running = 0; |
283 |
|
cmdpath = getpath(av[0], getenv("PATH"), X_OK); |
284 |
< |
cmdstr = quoted_cmdline(cmdpath, av); |
284 |
> |
cmdstr = quoted_cmdline(cmdpath, av+1); |
285 |
|
if (cmdstr == NULL) { return 0; } |
286 |
|
return start_process(proc, cmdstr); |
287 |
|
} |
288 |
|
|
289 |
|
|
290 |
+ |
int win_kill(RT_PID pid, int sig) /* we ignore sig... */ |
291 |
+ |
{ |
292 |
+ |
HANDLE hProc; |
293 |
+ |
|
294 |
+ |
hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid); |
295 |
+ |
/* it looks like we want to ignore errors here */ |
296 |
+ |
if(hProc != NULL) { |
297 |
+ |
#ifdef OBSOLETE_WINDOWS |
298 |
+ |
#define KILL_TIMEOUT 10 * 1000 /* milliseconds */ |
299 |
+ |
/* it might have some windows open... */ |
300 |
+ |
EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM)pid); |
301 |
+ |
if(WaitForSingleObject(hProc, KILL_TIMEOUT)!=WAIT_OBJECT_0) { |
302 |
+ |
/* No way to avoid dangling DLLs here. */ |
303 |
+ |
TerminateProcess(hProc, 0); |
304 |
+ |
} |
305 |
+ |
#else |
306 |
+ |
SafeTerminateProcess(hProc, 0); |
307 |
+ |
#endif |
308 |
+ |
/* WaitForSingleObject(hProc, 0); */ |
309 |
+ |
/* not much use to wait on Windows */ |
310 |
+ |
CloseHandle(hProc); |
311 |
+ |
} |
312 |
+ |
return 0; /* XXX we need to figure out more here... */ |
313 |
+ |
} |
314 |
+ |
|
315 |
+ |
|
316 |
|
int |
317 |
|
close_process(SUBPROC *proc) { |
318 |
|
int icres, ocres; |
319 |
|
DWORD pid; |
287 |
– |
HANDLE hProc; |
320 |
|
|
321 |
|
ocres = close(proc->w); |
322 |
|
icres = close(proc->r); |
323 |
|
pid = proc->pid; |
324 |
|
if(ocres != 0 || icres != 0) { |
293 |
– |
hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid); |
325 |
|
/* something went wrong: enforce infanticide */ |
326 |
|
/* other than that, it looks like we want to ignore errors here */ |
327 |
|
if (proc->running) { |
328 |
< |
if(hProc != NULL) { |
298 |
< |
#ifdef OBSOLETE_WINDOWS |
299 |
< |
#define KILL_TIMEOUT 10 * 1000 /* milliseconds */ |
300 |
< |
/* it might have some windows open... */ |
301 |
< |
EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM)pid); |
302 |
< |
if(WaitForSingleObject(hProc, KILL_TIMEOUT)!=WAIT_OBJECT_0) { |
303 |
< |
/* No way to avoid dangling DLLs here. */ |
304 |
< |
TerminateProcess(hProc, 0); |
305 |
< |
} |
306 |
< |
#else |
307 |
< |
SafeTerminateProcess(hProc, 0); |
308 |
< |
#endif |
309 |
< |
/* WaitForSingleObject(hProc, 0); */ |
310 |
< |
/* not much use to wait on Windows */ |
311 |
< |
CloseHandle(hProc); |
312 |
< |
} |
328 |
> |
win_kill(pid, 0); |
329 |
|
} |
330 |
|
} |
331 |
|
proc->running = 0; |