| 32 |
|
if (pd->pid > 0) |
| 33 |
|
return(-1); /* need to close, first */ |
| 34 |
|
|
| 35 |
< |
if ((pd->flags & (PF_FILT_INP|PF_FILT_OUT)) == (PF_FILT_INP|PF_FILT_OUT)) |
| 35 |
> |
if ((pd->flags&(PF_FILT_INP|PF_FILT_OUT)) == (PF_FILT_INP|PF_FILT_OUT)) |
| 36 |
|
return(-1); /* circular process not supported */ |
| 37 |
|
|
| 38 |
|
pd->flags &= ~PF_RUNNING; /* not running for sure */ |
| 58 |
|
p1[1] = pd->w; |
| 59 |
|
} else if (pipe(p1) < 0) |
| 60 |
|
return(-1); |
| 61 |
– |
#ifdef BSD |
| 62 |
– |
if (compath != NULL) |
| 63 |
– |
pd->pid = vfork(); /* more efficient with exec() */ |
| 64 |
– |
else |
| 65 |
– |
#endif |
| 61 |
|
pd->pid = fork(); |
| 62 |
|
if (pd->pid == 0) { /* if child... */ |
| 63 |
|
close(p0[1]); |
| 107 |
|
* No use in read stream without it, so set flag there as well. |
| 108 |
|
* GW: This bug took me two days to figure out!! |
| 109 |
|
*/ |
| 110 |
< |
if (pd->r >= 0) |
| 110 |
> |
if (pd->r > 0) |
| 111 |
|
fcntl(pd->r, F_SETFD, FD_CLOEXEC); |
| 112 |
< |
if (pd->w >= 0) |
| 112 |
> |
if (pd->w > 1) |
| 113 |
|
fcntl(pd->w, F_SETFD, FD_CLOEXEC); |
| 114 |
|
pd->flags |= PF_RUNNING; |
| 115 |
|
return(PIPE_BUF); |
| 123 |
|
) |
| 124 |
|
{ |
| 125 |
|
int togo = nproc; |
| 126 |
< |
int status, rtn_status = 0; |
| 126 |
> |
int status = 0, rtn_status = 0; |
| 127 |
|
RT_PID pid; |
| 128 |
|
int i; |
| 129 |
|
|
| 130 |
|
for (i = 0; i < nproc; i++) /* close pipes, first */ |
| 131 |
|
if (pd[i].flags & PF_RUNNING) { |
| 132 |
< |
close(pd[i].w); |
| 133 |
< |
close(pd[i].r); |
| 132 |
> |
if (pd[i].w >= 0) close(pd[i].w); |
| 133 |
> |
if (pd[i].r >= 0) close(pd[i].r); |
| 134 |
|
pd[i].flags &= ~PF_RUNNING; |
| 135 |
|
} else |
| 136 |
|
togo -= (pd[i].pid < 0); |
| 137 |
|
if (nproc == 1) { /* await specific process? */ |
| 143 |
– |
status = 0; |
| 138 |
|
if (waitpid(pd->pid, &status, 0) != pd->pid) |
| 139 |
|
return(-1); |
| 140 |
|
*pd = sp_inactive; |
| 143 |
|
/* else unordered wait */ |
| 144 |
|
while (togo > 0 && (pid = wait(&status)) >= 0) { |
| 145 |
|
for (i = nproc; i-- > 0; ) |
| 146 |
< |
if (pd[i].pid == pid) { |
| 147 |
< |
pd[i] = sp_inactive; |
| 154 |
< |
--togo; |
| 155 |
< |
break; |
| 156 |
< |
} |
| 146 |
> |
if (pd[i].pid == pid) |
| 147 |
> |
break; /* found it! */ |
| 148 |
|
if (i < 0) |
| 149 |
< |
continue; /* child we don't know? */ |
| 149 |
> |
continue; /* or child not in our list */ |
| 150 |
> |
pd[i] = sp_inactive; |
| 151 |
> |
--togo; |
| 152 |
|
status = status>>8 & 0xff; |
| 153 |
|
if (status) /* record non-zero status */ |
| 154 |
|
rtn_status = status; |