ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/win_process.c
(Generate patch)

Comparing ray/src/common/win_process.c (file contents):
Revision 3.5 by schorsch, Sat Oct 23 18:55:52 2004 UTC vs.
Revision 3.13 by schorsch, Mon Mar 28 16:59:38 2016 UTC

# Line 38 | Line 38 | win_nice(int inc) /* simple nice(2) replacement for Wi
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;
# Line 78 | Line 77 | BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitC
77          if ( !bSuccess ) SetLastError(dwErr);
78          return bSuccess;
79   }
81 #endif
80  
81  
82   static int
# Line 167 | Line 165 | start_process(SUBPROC *proc, char *cmdstr)
165          CloseHandle(hFromChildWrite); hFromChildWrite = NULL;
166          CloseHandle(hToChildRead); hToChildRead = NULL;
167          /* get the file descriptors */
168 <        proc->r = _open_osfhandle((long)hRead, _O_RDONLY);
169 <        proc->w = _open_osfhandle((long)hWrite, _O_APPEND);
168 >        proc->r = _open_osfhandle((long)hRead, _O_RDONLY|_O_BINARY);
169 >        proc->w = _open_osfhandle((long)hWrite, _O_APPEND|_O_BINARY);
170          proc->pid = PInfo.dwProcessId;
171          proc->running = 1;
172          CloseHandle(hCurProc);
# Line 185 | Line 183 | error: /* cleanup */
183          if(hWrite) CloseHandle(hWrite);
184          if(hCurProc) CloseHandle(hCurProc);
185          proc->running = 0;
186 <        return 0;
186 >        return -1;
187          /* There... Are we happy now? */
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) {
# Line 245 | Line 243 | char *sl[]       /* list of arguments */
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++) {
# Line 279 | Line 277 | open_process(SUBPROC *proc, char *av[])
277          char *cmdpath;
278          char *cmdstr;
279  
280 +        if (av == NULL || av[0] == NULL) {
281 +                fputs("Illegal call to open_process()!\n", stderr);
282 +                return -1;
283 +        }
284 +        proc->pid = 0;
285          proc->running = 0;
286 +        if (av == NULL) { return -1; }
287          cmdpath = getpath(av[0], getenv("PATH"), X_OK);
288 <        cmdstr = quoted_cmdline(cmdpath, av);
288 >        cmdstr = quoted_cmdline(cmdpath, av+1);
289          if (cmdstr == NULL) { return 0; }
290          return start_process(proc, cmdstr);
291   }
# Line 294 | Line 298 | int win_kill(RT_PID pid, int sig) /* we ignore sig...
298          hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE, pid);
299          /*  it looks like we want to ignore errors here */
300          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
301                  SafeTerminateProcess(hProc, 0);
307 #endif
308                /* WaitForSingleObject(hProc, 0); */
309                /* not much use to wait on Windows */
302                  CloseHandle(hProc);
303          }
304          return 0; /* XXX we need to figure out more here... */
# Line 314 | Line 306 | int win_kill(RT_PID pid, int sig) /* we ignore sig...
306  
307  
308   int
309 < close_process(SUBPROC *proc) {
310 <        int icres, ocres;
309 > close_processes(SUBPROC pd[], int nproc) {
310 >        int i, icres, ocres;
311          DWORD pid;
312  
313 <        ocres = close(proc->w);
314 <        icres = close(proc->r);
315 <        pid = proc->pid;
316 <        if(ocres != 0 || icres != 0) {
317 <                /* something went wrong: enforce infanticide */
318 <                /* other than that, it looks like we want to ignore errors here */
319 <                if (proc->running) {
320 <                        int win_kill(pid, 0);
313 >        for (i = 0; i < nproc; i++) {
314 >                if (pd[i].running) {
315 >                        ocres = close(pd[i].w);
316 >                        icres = close(pd[i].r);
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 */
321 >                                win_kill(pd[i].pid, 0);
322 >                        }
323                  }
324 +                pd[i].pid = 0;
325          }
331        proc->running = 0;
326          return 0; /* XXX we need to figure out more here... */
327   }
328  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines