-fix error reporting, remove unnecessary syscalls on some paths
authorChristian Grothoff <christian@grothoff.org>
Sat, 28 Jan 2012 14:23:43 +0000 (14:23 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 28 Jan 2012 14:23:43 +0000 (14:23 +0000)
src/util/disk.c

index a044482f1fccc13f21e0f1a4e19c78d29199aa29..6fe2ebe8fd5a502b6809a784565ebf0e7c5fd43e 100644 (file)
@@ -2148,28 +2148,43 @@ GNUNET_DISK_pipe (int blocking_read, int blocking_write, int inherit_read, int i
   p->fd[0]->fd = fd[0];
   p->fd[1]->fd = fd[1];
   ret = 0;
-  flags = fcntl (fd[0], F_GETFL);
   if (!blocking_read)
+  {
+    flags = fcntl (fd[0], F_GETFL);
     flags |= O_NONBLOCK;
-  if (0 > fcntl (fd[0], F_SETFL, flags))
-    ret = -1;
+    if (0 > fcntl (fd[0], F_SETFL, flags))
+    {
+      ret = -1;
+      eno = errno;
+    }
+  }
   flags = fcntl (fd[0], F_GETFD);
   flags |= FD_CLOEXEC;
   if (0 > fcntl (fd[0], F_SETFD, flags))
+  {
     ret = -1;
+    eno = errno;
+  }
 
-  flags = fcntl (fd[1], F_GETFL);
   if (!blocking_write)
+  {
+    flags = fcntl (fd[1], F_GETFL);
     flags |= O_NONBLOCK;
-  if (0 > fcntl (fd[1], F_SETFL, flags))
-    ret = -1;
+    if (0 > fcntl (fd[1], F_SETFL, flags))
+    {
+      ret = -1;
+      eno = errno;
+    }
+  }
   flags = fcntl (fd[1], F_GETFD);
   flags |= FD_CLOEXEC;
   if (0 > fcntl (fd[1], F_SETFD, flags))
+  {
     ret = -1;
+    eno = errno;
+  }
   if (ret == -1)
   {
-    eno = errno;
     LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fcntl");
     GNUNET_break (0 == close (p->fd[0]->fd));
     GNUNET_break (0 == close (p->fd[1]->fd));