diff options
author | Noah Watkins <noahwatkins@gmail.com> | 2013-07-20 18:41:40 -0700 |
---|---|---|
committer | Noah Watkins <noahwatkins@gmail.com> | 2013-07-20 18:41:40 -0700 |
commit | a7922e732f7906d903e2413aa818ab187dd1bc9b (patch) | |
tree | 4392c653c1b38adc1dbb8fffdbbcecd6ef748c79 | |
parent | 339c1d462942e4c17a6104a5d91ddad78258e17f (diff) | |
download | ceph-a7922e732f7906d903e2413aa818ab187dd1bc9b.tar.gz |
pipe: use feature tests for pipe2 and O_CLOEXEC
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/common/pipe_util.c | 35 |
2 files changed, 22 insertions, 14 deletions
diff --git a/configure.ac b/configure.ac index 1331267bdc1..c08d5d84cbf 100644 --- a/configure.ac +++ b/configure.ac @@ -543,6 +543,7 @@ AC_CHECK_HEADERS([sys/prctl.h]) AC_CHECK_FUNCS([prctl]) AC_CHECK_FUNCS([posix_fadvise]) AC_CHECK_FUNCS([sem_timedwait]) +AC_CHECK_FUNCS([pipe2]) AC_CHECK_HEADERS([sys/vfs.h sys/mount.h]) diff --git a/src/common/pipe_util.c b/src/common/pipe_util.c index b71e29265f8..ee15addcdfd 100644 --- a/src/common/pipe_util.c +++ b/src/common/pipe_util.c @@ -11,6 +11,7 @@ * Foundation. See file COPYING. * */ +#include <acconfig.h> #include "common/pipe_util.h" @@ -18,26 +19,32 @@ #include <fcntl.h> #include <unistd.h> +#include <sys/fcntl.h> /* O_CLOEXEC on OSX 10.8 */ + int pipe_cloexec(int pipefd[2]) { -#if defined(O_CLOEXEC) && !defined(__FreeBSD__) int ret; + +#ifdef HAVE_PIPE2 +#ifdef O_CLOEXEC ret = pipe2(pipefd, O_CLOEXEC); - if (ret) { - ret = -errno; - return ret; - } - 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 = -errno; - return ret; - } + ret = pipe2(pipefd, 0); +#endif +#else + ret = pipe(pipefd); +#endif + if (ret) + return -errno; + +#if !defined(HAVE_PIPE2) || !defined(O_CLOEXEC) + /* + * The old-fashioned, race-condition prone way that we have to fall + * back on if O_CLOEXEC does not exist. + */ fcntl(pipefd[0], F_SETFD, FD_CLOEXEC); fcntl(pipefd[1], F_SETFD, FD_CLOEXEC); - return 0; #endif + + return 0; } |