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.4 by greg, Tue Nov 11 16:24:06 2003 UTC vs.
Revision 3.8 by schorsch, Wed Jun 7 17:52:03 2006 UTC

# Line 12 | Line 12 | static const char      RCSid[] = "$Id$";
12  
13   #include <sys/types.h>
14   #include <sys/wait.h>
15 + #include <fcntl.h>
16 + #include <stdlib.h>
17  
18   #include "rtprocess.h"
19 + #include "rtio.h"
20  
21  
22   int
# Line 22 | Line 25 | SUBPROC *pd,
25   char    *av[]
26   )
27   {
25        extern char     *getpath(), *getenv();
28          char    *compath;
29          int     p0[2], p1[2];
30  
# Line 54 | Line 56 | char   *av[]
56          close(p1[1]);
57          pd->r = p1[0];
58          pd->w = p0[1];
59 +        /*
60 +         * Close write stream on exec to avoid multiprocessing deadlock.
61 +         * No use in read stream without it, so set flag there as well.
62 +         * GW: This bug took me two days to figure out!!
63 +         */
64 +        fcntl(pd->r, F_SETFD, FD_CLOEXEC);
65 +        fcntl(pd->w, F_SETFD, FD_CLOEXEC);
66          pd->running = 1;
67          return(PIPE_BUF);
68   }
# Line 65 | Line 74 | close_process(         /* close pipes and wait for process */
74   SUBPROC *pd
75   )
76   {
77 <        int     pid, status;
77 >        int     status;
78  
79 +        if (!pd->running)
80 +                return(0);
81          close(pd->r);
82          close(pd->w);
83          pd->running = 0;
84 <        while ((pid = wait(&status)) != -1)
85 <                if (pid == pd->pid)
75 <                        return(status>>8 & 0xff);
84 >        if (waitpid(pd->pid, &status, 0) == pd->pid)
85 >                return(status>>8 & 0xff);
86          return(-1);             /* ? unknown status */
87   }
88  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines