diff --git a/src/unix/internal.h b/src/unix/internal.h index 8a28b2aa09..23f16f7b0e 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -168,8 +168,12 @@ void uv__timer_close(uv_timer_t* handle); void uv__udp_close(uv_udp_t* handle); void uv__udp_finish_close(uv_udp_t* handle); -#define UV__F_IPC (1 << 0) -#define UV__F_NONBLOCK (1 << 1) +#ifdef UV__O_NONBLOCK +# define UV__F_NONBLOCK UV__O_NONBLOCK +#else +# define UV__F_NONBLOCK 1 +#endif + int uv__make_socketpair(int fds[2], int flags); int uv__make_pipe(int fds[2], int flags); diff --git a/src/unix/process.c b/src/unix/process.c index d3eb998c1b..230afe991f 100644 --- a/src/unix/process.c +++ b/src/unix/process.c @@ -68,25 +68,15 @@ static void uv__chld(EV_P_ ev_child* watcher, int revents) { int uv__make_socketpair(int fds[2], int flags) { -#ifdef SOCK_NONBLOCK - int fl; - - fl = SOCK_CLOEXEC; - - if (flags & UV__F_NONBLOCK) - fl |= SOCK_NONBLOCK; - - if (socketpair(AF_UNIX, SOCK_STREAM|fl, 0, fds) == 0) +#if __linux__ + if (socketpair(AF_UNIX, SOCK_STREAM | UV__SOCK_CLOEXEC | flags, 0, fds) == 0) return 0; + /* Retry on EINVAL, it means SOCK_CLOEXEC is not supported. + * Anything else is a genuine error. + */ if (errno != EINVAL) return -1; - - /* errno == EINVAL so maybe the kernel headers lied about - * the availability of SOCK_NONBLOCK. This can happen if people - * build libuv against newer kernel headers than the kernel - * they actually run the software on. - */ #endif if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) @@ -106,14 +96,7 @@ int uv__make_socketpair(int fds[2], int flags) { int uv__make_pipe(int fds[2], int flags) { #if __linux__ - int fl; - - fl = UV__O_CLOEXEC; - - if (flags & UV__F_NONBLOCK) - fl |= UV__O_NONBLOCK; - - if (uv__pipe2(fds, fl) == 0) + if (uv__pipe2(fds, flags | UV__O_CLOEXEC) == 0) return 0; if (errno != ENOSYS)