28 |
|
char *compath; |
29 |
|
int p0[2], p1[2]; |
30 |
|
|
31 |
< |
pd->running = 0; /* not yet */ |
32 |
< |
/* find executable */ |
33 |
< |
compath = getpath(av[0], getenv("PATH"), 1); |
34 |
< |
if (compath == 0) |
31 |
> |
pd->running = 0; /* not going yet */ |
32 |
> |
|
33 |
> |
if (av == NULL) /* cloning operation? */ |
34 |
> |
compath = NULL; |
35 |
> |
else if ((compath = getpath(av[0], getenv("PATH"), X_OK)) == NULL) |
36 |
|
return(0); |
37 |
|
if (pipe(p0) < 0 || pipe(p1) < 0) |
38 |
|
return(-1); |
39 |
< |
if ((pd->pid = fork()) == 0) { /* if child */ |
39 |
> |
if ((pd->pid = fork()) == 0) { /* if child... */ |
40 |
|
close(p0[1]); |
41 |
|
close(p1[0]); |
42 |
|
if (p0[0] != 0) { /* connect p0 to stdin */ |
47 |
|
dup2(p1[1], 1); |
48 |
|
close(p1[1]); |
49 |
|
} |
50 |
< |
execv(compath, av); /* exec command */ |
50 |
> |
if (compath == NULL) /* just cloning? */ |
51 |
> |
return(0); |
52 |
> |
execv(compath, av); /* else exec command */ |
53 |
|
perror(compath); |
54 |
|
_exit(127); |
55 |
|
} |
81 |
|
|
82 |
|
if (!pd->running) |
83 |
|
return(0); |
81 |
– |
close(pd->r); |
84 |
|
close(pd->w); |
85 |
+ |
close(pd->r); |
86 |
|
pd->running = 0; |
87 |
|
if (waitpid(pd->pid, &status, 0) == pd->pid) |
88 |
|
return(status>>8 & 0xff); |
89 |
+ |
|
90 |
|
return(-1); /* ? unknown status */ |
91 |
|
} |
92 |
|
|