4 #include "threadimpl.h"
6 #define PIPEMNT "/mnt/temp"
9 procexec(Channel *pidc, char *prog, char *args[])
15 _threaddebug(DBGEXEC, "procexec %s", prog);
16 /* must be only thread in proc */
19 if(p->threads.head != t || p->threads.head->nextt != nil){
20 werrstr("not only thread in proc");
28 * We want procexec to behave like exec; if exec succeeds,
29 * never return, and if it fails, return with errstr set.
30 * Unfortunately, the exec happens in another proc since
31 * we have to wait for the exec'ed process to finish.
32 * To provide the semantics, we open a pipe with the
33 * write end close-on-exec and hand it to the proc that
34 * is doing the exec. If the exec succeeds, the pipe will
35 * close so that our read below fails. If the exec fails,
36 * then the proc doing the exec sends the errstr down the
39 if(bind("#|", PIPEMNT, MREPL) < 0)
41 if((p->exec.fd[0] = open(PIPEMNT "/data", OREAD)) < 0){
42 unmount(nil, PIPEMNT);
45 if((p->exec.fd[1] = open(PIPEMNT "/data1", OWRITE|OCEXEC)) < 0){
47 unmount(nil, PIPEMNT);
50 unmount(nil, PIPEMNT);
52 /* exec in parallel via the scheduler */
53 assert(p->needexec==0);
60 if((n = read(p->exec.fd[0], p->exitstr, ERRMAX-1)) > 0){ /* exec failed */
62 errstr(p->exitstr, ERRMAX);
71 /* wait for exec'ed program, then exit */
76 procexecl(Channel *pidc, char *f, ...)
78 procexec(pidc, f, &f+1);