| 28 |
|
char *compath; |
| 29 |
|
int p0[2], p1[2]; |
| 30 |
|
|
| 31 |
+ |
pd->pid = -1; |
| 32 |
|
pd->running = 0; /* not going yet */ |
| 33 |
|
|
| 34 |
|
if (av == NULL) /* cloning operation? */ |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
|
| 74 |
– |
|
| 75 |
|
int |
| 76 |
< |
close_process( /* close pipes and wait for process */ |
| 77 |
< |
SUBPROC *pd |
| 76 |
> |
close_processes( /* close pipes and wait for processes to finish */ |
| 77 |
> |
SUBPROC pd[], |
| 78 |
> |
int nproc |
| 79 |
|
) |
| 80 |
|
{ |
| 81 |
< |
int status; |
| 81 |
> |
int togo = nproc; |
| 82 |
> |
int status, rtn_status = 0; |
| 83 |
> |
RT_PID pid; |
| 84 |
> |
int i; |
| 85 |
|
|
| 86 |
< |
if (!pd->running) |
| 87 |
< |
return(0); |
| 88 |
< |
close(pd->w); |
| 89 |
< |
close(pd->r); |
| 90 |
< |
pd->running = 0; |
| 91 |
< |
if (waitpid(pd->pid, &status, 0) == pd->pid) |
| 86 |
> |
for (i = 0; i < nproc; i++) /* close pipes, first */ |
| 87 |
> |
if (pd[i].running) { |
| 88 |
> |
close(pd[i].w); |
| 89 |
> |
close(pd[i].r); |
| 90 |
> |
pd[i].running = 0; |
| 91 |
> |
} else |
| 92 |
> |
togo -= (pd[i].pid < 0); |
| 93 |
> |
if (nproc == 1) { /* await specific process? */ |
| 94 |
> |
if (waitpid(pd->pid, &status, 0) != pd->pid) |
| 95 |
> |
return(-1); |
| 96 |
> |
pd->pid = -1; |
| 97 |
|
return(status>>8 & 0xff); |
| 98 |
< |
|
| 99 |
< |
return(-1); /* ? unknown status */ |
| 98 |
> |
} |
| 99 |
> |
/* else unordered wait */ |
| 100 |
> |
while (togo > 0 && (pid = wait(&status)) >= 0) { |
| 101 |
> |
for (i = nproc; i-- > 0; ) |
| 102 |
> |
if (pd[i].pid == pid) { |
| 103 |
> |
pd[i].pid = -1; |
| 104 |
> |
--togo; |
| 105 |
> |
break; |
| 106 |
> |
} |
| 107 |
> |
if (i < 0) |
| 108 |
> |
continue; /* child we don't know? */ |
| 109 |
> |
status = status>>8 & 0xff; |
| 110 |
> |
if (status) /* record non-zero status */ |
| 111 |
> |
rtn_status = status; |
| 112 |
> |
} |
| 113 |
> |
if (togo) /* child went missing? */ |
| 114 |
> |
return(-1); |
| 115 |
> |
return(rtn_status); |
| 116 |
|
} |
| 92 |
– |
|
| 93 |
– |
|