diff options
Diffstat (limited to 'src/libthread/exec-unix.c')
-rw-r--r-- | src/libthread/exec-unix.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/libthread/exec-unix.c b/src/libthread/exec-unix.c index ef50bf19..97c75607 100644 --- a/src/libthread/exec-unix.c +++ b/src/libthread/exec-unix.c @@ -3,7 +3,7 @@ #include "threadimpl.h" void -procexec(Channel *pidc, char *prog, char *args[]) +procexec(Channel *pidc, int fd[3], char *prog, char *args[]) { int n; Proc *p; @@ -45,6 +45,7 @@ procexec(Channel *pidc, char *prog, char *args[]) assert(p->needexec==0); p->exec.prog = prog; p->exec.args = args; + p->exec.stdfd = fd; p->needexec = 1; _sched(); @@ -56,7 +57,11 @@ procexec(Channel *pidc, char *prog, char *args[]) goto Bad; } close(p->exec.fd[0]); - + close(fd[0]); + if(fd[1] != fd[0]) + close(fd[1]); + if(fd[2] != fd[1] && fd[2] != fd[0]) + close(fd[2]); if(pidc) sendul(pidc, t->ret); @@ -66,9 +71,9 @@ procexec(Channel *pidc, char *prog, char *args[]) } void -procexecl(Channel *pidc, char *f, ...) +procexecl(Channel *pidc, int fd[3], char *f, ...) { - procexec(pidc, f, &f+1); + procexec(pidc, fd, f, &f+1); } void @@ -107,10 +112,17 @@ efork(void *ve) { char buf[ERRMAX]; Execargs *e; + int i; e = ve; _threaddebug(DBGEXEC, "_schedexec %s -- calling execv", e->prog); - execv(e->prog, e->args); + dup(e->stdfd[0], 0); + dup(e->stdfd[1], 1); + dup(e->stdfd[2], 2); + for(i=3; i<40; i++) + if(i != e->fd[1]) + close(i); + execvp(e->prog, e->args); _threaddebug(DBGEXEC, "_schedexec failed: %r"); rerrstr(buf, sizeof buf); if(buf[0]=='\0') |