]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pipe: use pipe2 feature test; check fcntl retval 793/head
authorNoah Watkins <noahwatkins@gmail.com>
Sun, 21 Jul 2013 01:41:40 +0000 (18:41 -0700)
committerSage Weil <sage@inktank.com>
Fri, 1 Nov 2013 23:21:14 +0000 (16:21 -0700)
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
configure.ac
src/common/pipe.c

index c344e7d6134b6f15746298036c913512cc9d6755..66d8f2161c99054347fd87a014b6372e34b2891f 100644 (file)
@@ -538,6 +538,7 @@ AC_CHECK_FUNC([fallocate],
 
 AC_CHECK_HEADERS([sys/prctl.h])
 AC_CHECK_FUNCS([prctl])
+AC_CHECK_FUNCS([pipe2])
 
 # Checks for typedefs, structures, and compiler characteristics.
 #AC_HEADER_STDBOOL
index 9c01b322f89dc3315bbade3faa406c677234cf47..9ec9e36e586ba64e1a6770a2fc4a1a9295b4234e 100644 (file)
@@ -11,6 +11,7 @@
  * Foundation.  See file COPYING.
  *
  */
+#include "acconfig.h"
 
 #include "common/pipe.h"
 
 
 int pipe_cloexec(int pipefd[2])
 {
-#if defined(O_CLOEXEC) && !defined(__FreeBSD__)
        int ret;
+
+#if defined(HAVE_PIPE2) && defined(O_CLOEXEC)
        ret = pipe2(pipefd, O_CLOEXEC);
-       if (ret) {
-               ret = -errno;
-               return ret;
-       }
+       if (ret == -1)
+               return -errno;
        return 0;
 #else
-       /* The old-fashioned, race-condition prone way that we have to fall back on if
-        * O_CLOEXEC does not exist. */
-       int ret = pipe(pipefd);
-       if (ret) {
+       ret = pipe(pipefd);
+       if (ret == -1)
+               return -errno;
+
+       /*
+        * The old-fashioned, race-condition prone way that we have to fall
+        * back on if O_CLOEXEC does not exist.
+        */
+       ret = fcntl(pipefd[0], F_SETFD, FD_CLOEXEC);
+       if (ret == -1) {
+               ret = -errno;
+               goto out;
+       }
+
+       ret = fcntl(pipefd[1], F_SETFD, FD_CLOEXEC);
+       if (ret == -1) {
                ret = -errno;
-               return ret;
+               goto out;
        }
-       fcntl(pipefd[0], F_SETFD, FD_CLOEXEC);
-       fcntl(pipefd[1], F_SETFD, FD_CLOEXEC);
+
        return 0;
+
+out:
+       TEMP_FAILURE_RETRY(close(pipefd[0]));
+       TEMP_FAILURE_RETRY(close(pipefd[1]));
+
+       return ret;
 #endif
 }