12 |
|
|
13 |
|
#include <sys/types.h> |
14 |
|
#include <sys/wait.h> |
15 |
+ |
#include <fcntl.h> |
16 |
|
|
17 |
|
#include "rtprocess.h" |
18 |
|
|
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 */ |
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 |
|
} |
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) |
75 |
< |
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 |
|
|