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

Comparing ray/src/common/unix_process.c (file contents):
Revision 3.1 by schorsch, Thu Jun 26 00:58:09 2003 UTC vs.
Revision 3.6 by greg, Sun Sep 19 08:42:22 2004 UTC

# Line 10 | Line 10 | static const char      RCSid[] = "$Id$";
10  
11   #include "copyright.h"
12  
13 + #include <sys/types.h>
14 + #include <sys/wait.h>
15 + #include <fcntl.h>
16 +
17   #include "rtprocess.h"
14 #include  "vfork.h"
18  
19  
20   int
# Line 31 | Line 34 | char   *av[]
34                  return(0);
35          if (pipe(p0) < 0 || pipe(p1) < 0)
36                  return(-1);
37 <        if ((pd->pid = vfork()) == 0) {         /* if child */
37 >        if ((pd->pid = fork()) == 0) {          /* if child */
38                  close(p0[1]);
39                  close(p1[0]);
40                  if (p0[0] != 0) {       /* connect p0 to stdin */
# Line 52 | Line 55 | char   *av[]
55          close(p1[1]);
56          pd->r = p1[0];
57          pd->w = p0[1];
58 +        /*
59 +         * Close write stream on exec to avoid multiprocessing deadlock.
60 +         * No use in read stream without it, so set flag there as well.
61 +         * GW: This bug took me two days to figure out!!
62 +         */
63 +        fcntl(pd->r, F_SETFD, FD_CLOEXEC);
64 +        fcntl(pd->w, F_SETFD, FD_CLOEXEC);
65          pd->running = 1;
66          return(PIPE_BUF);
67   }
# Line 65 | Line 75 | SUBPROC *pd
75   {
76          int     pid, status;
77  
78 +        if (!pd->running)
79 +                return(0);
80          close(pd->r);
81          close(pd->w);
82          pd->running = 0;
83 <        while ((pid = wait(&status)) != -1)
84 <                if (pid == pd->pid)
73 <                        return(status>>8 & 0xff);
83 >        if (waitpid(pd->pid, &status, 0) == pd->pid)
84 >                return(status>>8 & 0xff);
85          return(-1);             /* ? unknown status */
86   }
87  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines