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.9 by greg, Wed Feb 12 00:15:40 2014 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 190 | Line 188 | error: /* cleanup */
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 283 | Line 281 | open_process(SUBPROC *proc, char *av[])
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);
# Line 299 | 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) {
302 #ifdef OBSOLETE_WINDOWS
303 #define KILL_TIMEOUT 10 * 1000 /* milliseconds */
304                /* it might have some windows open... */
305                EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM)pid);
306                if(WaitForSingleObject(hProc, KILL_TIMEOUT)!=WAIT_OBJECT_0) {
307                        /* No way to avoid dangling DLLs here. */
308                        TerminateProcess(hProc, 0);
309                }
310 #else
301                  SafeTerminateProcess(hProc, 0);
312 #endif
313                /* WaitForSingleObject(hProc, 0); */
314                /* not much use to wait on Windows */
302                  CloseHandle(hProc);
303          }
304          return 0; /* XXX we need to figure out more here... */
# Line 319 | 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 <                        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          }
336        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