fix setting close on exec
authorChristian Grothoff <christian@grothoff.org>
Wed, 20 Oct 2010 13:12:00 +0000 (13:12 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 20 Oct 2010 13:12:00 +0000 (13:12 +0000)
src/util/disk.c

index 65509166e1bac25da8bcb4928d0996f9d273669a..265295922fffbad5dc047c0ad465e3f4906beb2f 100644 (file)
@@ -1642,6 +1642,7 @@ GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h)
 #endif
 }
 
+
 /**
  * Creates an interprocess channel
  *
@@ -1672,24 +1673,34 @@ GNUNET_DISK_pipe (int blocking, int inherit_read, int inherit_write)
   ret = pipe (fd);
   if (ret == -1)
     {
+      eno = errno;
+      GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe");
       GNUNET_free (p);
+      errno = eno;
       return NULL;
     }
   p->fd[0]->fd = fd[0];
   p->fd[1]->fd = fd[1];
   ret = 0;
   flags = fcntl (fd[0], F_GETFL);
-  flags |= FD_CLOEXEC;
   if (!blocking)
     flags |= O_NONBLOCK;
   if (0 > fcntl (fd[0], F_SETFL, flags))
     ret = -1;
-  flags = fcntl (fd[1], F_GETFL);
+  flags = fcntl (fd[0], F_GETFD);
   flags |= FD_CLOEXEC;
+  if (0 > fcntl (fd[0], F_SETFD, flags))
+    ret = -1;
+
+  flags = fcntl (fd[1], F_GETFL);
   if (!blocking)
     flags |= O_NONBLOCK;
   if (0 > fcntl (fd[1], F_SETFL, flags))
     ret = -1;
+  flags = fcntl (fd[1], F_GETFD);
+  flags |= FD_CLOEXEC;
+  if (0 > fcntl (fd[1], F_SETFD, flags))
+    ret = -1;
   if (ret == -1)
     {
       eno = errno;