]> git.lizzy.rs Git - plan9front.git/commitdiff
libthread: use devdup instead of mounting pipe to /mnt/temp for close-on-exec in...
authorcinap_lenrek <cinap_lenrek@felloff.net>
Sat, 28 Feb 2015 11:50:17 +0000 (12:50 +0100)
committercinap_lenrek <cinap_lenrek@felloff.net>
Sat, 28 Feb 2015 11:50:17 +0000 (12:50 +0100)
the namespace might be shared by other processes. instead, we
create a anonymous pipe with pipe() and use devdup to open one
end close-on-exec. this is shorter and avoids the race condition.

do not touch Execargs after writing the error message as the
process might be gone after the write. this was to manually
close the fd which isnt neccesary as the kernel will do it
for us on the following exit.

sys/man/2/thread
sys/src/libthread/exec.c
sys/src/libthread/main.c

index b06e31b964fe1af0a34924c6fe4c1608a694ab12..3b93eef9e3a1d6253c8be4cd71d8e08a193b3e5f 100644 (file)
@@ -356,11 +356,6 @@ can safely free it once they have
 received the
 .I cpid
 response.
-Note that the mount point
-.B /mnt/temp
-must exist;
-.I procexec(l)
-mount pipes there.
 .PP
 .I Threadwaitchan
 returns a channel of pointers to
index b93eeb28fa26cf5f6078829dca87c5e3335ef347..3bfbda3c62d84b9398468574b52f44133504c008 100644 (file)
@@ -3,8 +3,6 @@
 #include <thread.h>
 #include "threadimpl.h"
 
-#define PIPEMNT        "/mnt/temp"
-
 void
 procexec(Channel *pidc, char *prog, char *args[])
 {
@@ -36,18 +34,16 @@ procexec(Channel *pidc, char *prog, char *args[])
         * then the proc doing the exec sends the errstr down the
         * pipe to us.
         */
-       if(bind("#|", PIPEMNT, MREPL) < 0)
-               goto Bad;
-       if((p->exec.fd[0] = open(PIPEMNT "/data", OREAD)) < 0){
-               unmount(nil, PIPEMNT);
+       if(pipe(p->exec.fd) < 0)
                goto Bad;
-       }
-       if((p->exec.fd[1] = open(PIPEMNT "/data1", OWRITE|OCEXEC)) < 0){
+       snprint(p->exitstr, ERRMAX, "/fd/%d", p->exec.fd[1]);
+       if((n = open(p->exitstr, OWRITE|OCEXEC)) < 0){
                close(p->exec.fd[0]);
-               unmount(nil, PIPEMNT);
+               close(p->exec.fd[1]);
                goto Bad;
        }
-       unmount(nil, PIPEMNT);
+       close(p->exec.fd[1]);
+       p->exec.fd[1] = n;
 
        /* exec in parallel via the scheduler */
        assert(p->needexec==0);
index 03c069c1442cdde1575f0f45e0f3e0e7b50fdd1d..708b65ed1641a0e9f0547a779a1bd90b70d2a900 100644 (file)
@@ -114,7 +114,6 @@ efork(Execargs *e)
        if(buf[0]=='\0')
                strcpy(buf, "exec failed");
        write(e->fd[1], buf, strlen(buf));
-       close(e->fd[1]);
        _exits(buf);
 }