--- ray/src/common/win_process.c 2005/09/19 11:30:10 3.6 +++ ray/src/common/win_process.c 2016/03/04 19:13:53 3.11 @@ -1,5 +1,5 @@ #ifndef lint -static char RCSid[]="$Id: win_process.c,v 3.6 2005/09/19 11:30:10 schorsch Exp $"; +static char RCSid[]="$Id: win_process.c,v 3.11 2016/03/04 19:13:53 greg Exp $"; #endif /* * Routines to communicate with separate process via dual pipes. @@ -167,8 +167,8 @@ start_process(SUBPROC *proc, char *cmdstr) CloseHandle(hFromChildWrite); hFromChildWrite = NULL; CloseHandle(hToChildRead); hToChildRead = NULL; /* get the file descriptors */ - proc->r = _open_osfhandle((long)hRead, _O_RDONLY); - proc->w = _open_osfhandle((long)hWrite, _O_APPEND); + proc->r = _open_osfhandle((long)hRead, _O_RDONLY|_O_BINARY); + proc->w = _open_osfhandle((long)hWrite, _O_APPEND|_O_BINARY); proc->pid = PInfo.dwProcessId; proc->running = 1; CloseHandle(hCurProc); @@ -185,7 +185,7 @@ error: /* cleanup */ if(hWrite) CloseHandle(hWrite); if(hCurProc) CloseHandle(hCurProc); proc->running = 0; - return 0; + return -1; /* There... Are we happy now? */ } @@ -279,7 +279,13 @@ open_process(SUBPROC *proc, char *av[]) char *cmdpath; char *cmdstr; + if (av == NULL || av[0] == NULL) { + fputs("Illegal call to open_process()!\n", stderr); + return -1; + } + proc->pid = 0; proc->running = 0; + if (av == NULL) { return -1; } cmdpath = getpath(av[0], getenv("PATH"), X_OK); cmdstr = quoted_cmdline(cmdpath, av+1); if (cmdstr == NULL) { return 0; } @@ -314,21 +320,23 @@ int win_kill(RT_PID pid, int sig) /* we ignore sig... int -close_process(SUBPROC *proc) { - int icres, ocres; +close_processes(SUBPROC pd[], int nproc) { + int i, icres, ocres; DWORD pid; - ocres = close(proc->w); - icres = close(proc->r); - pid = proc->pid; - if(ocres != 0 || icres != 0) { - /* something went wrong: enforce infanticide */ - /* other than that, it looks like we want to ignore errors here */ - if (proc->running) { - win_kill(pid, 0); + for (i = 0; i < nproc; i++) { + if (pid[i].running) { + ocres = close(pd[i].w); + icres = close(pd[i].r); + pd[i].running = 0; + if(ocres != 0 || icres != 0) { + /* something went wrong: enforce infanticide */ + /* other than that, it looks like we want to ignore errors here */ + win_kill(pd[i].pid, 0); + } } + pd[i].pid = 0; } - proc->running = 0; return 0; /* XXX we need to figure out more here... */ }