diff --git a/src/anet.c b/src/anet.c index 75471abd21..49334aa8e8 100644 --- a/src/anet.c +++ b/src/anet.c @@ -745,7 +745,7 @@ int anetFdToString(int fd, char *ip, size_t ip_len, int *port, int remote) { * and one of the use cases is O_CLOEXEC|O_NONBLOCK. */ int anetPipe(int fds[2], int read_flags, int write_flags) { int pipe_flags = 0; -#if defined(__linux__) || defined(__FreeBSD__) +#ifdef HAVE_PIPE2 /* When possible, try to leverage pipe2() to apply flags that are common to both ends. * There is no harm to set O_CLOEXEC to prevent fd leaks. */ pipe_flags = O_CLOEXEC | (read_flags & write_flags); diff --git a/src/config.h b/src/config.h index 4646f653ea..2ff920a2a2 100644 --- a/src/config.h +++ b/src/config.h @@ -106,6 +106,15 @@ #define HAVE_ACCEPT4 1 #endif +/* Detect for pipe2() */ +#if defined(__linux__) || \ + defined(__FreeBSD__) || \ + defined(OpenBSD5_7) || \ + (defined(__DragonFly__) && __DragonFly_version >= 400106) || \ + (defined(__NetBSD__) && (defined(NetBSD6_0) || __NetBSD_Version__ >= 600000000)) +#define HAVE_PIPE2 1 +#endif + #if (defined(__APPLE__) && defined(MAC_OS_10_6_DETECTED)) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined (__NetBSD__) #define HAVE_KQUEUE 1 #endif