No need to read from pipefd at the end of subproc
authorRobert Swiecki <swiecki@google.com>
Mon, 25 Apr 2016 14:06:19 +0000 (16:06 +0200)
committerRobert Swiecki <swiecki@google.com>
Mon, 25 Apr 2016 14:06:19 +0000 (16:06 +0200)
subproc.c

index 2ae1b4d5057ce2d18e80486add8b816c77559e44..cbc789f42614a5cf1cb7efe94324050e24c92016 100644 (file)
--- a/subproc.c
+++ b/subproc.c
@@ -247,16 +247,15 @@ void subprocRunChild(struct nsjconf_t *nsjconf, int fd_in, int fd_out, int fd_er
                PLOG_E("socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC) failed");
                return;
        }
-       int subproc_sock = sv[1];
-       defer {
-               close(subproc_sock);
-       };
 
        pid_t pid = syscall(__NR_clone, (uintptr_t) flags, NULL, NULL, NULL, (uintptr_t) 0);
        if (pid == 0) {
                close(sv[1]);
                subprocNewProc(nsjconf, fd_in, fd_out, fd_err, sv[0]);
        }
+       defer {
+               close(sv[1]);
+       }
        close(sv[0]);
        if (pid == -1) {
                PLOG_E("clone(flags=%#lx) failed. You probably need root privileges if your system "
@@ -274,7 +273,4 @@ void subprocRunChild(struct nsjconf_t *nsjconf, int fd_in, int fd_out, int fd_er
        char cs_addr[64];
        netConnToText(fd_in, true /* remote */ , cs_addr, sizeof(cs_addr), NULL);
        LOG_I("PID: %d about to execute '%s' for %s", pid, nsjconf->argv[0], cs_addr);
-
-       char buf[1024];
-       utilReadFromFd(sv[1], &buf, sizeof(buf));
 }