From ab6fc15a16978070239f8eb52f5418076aa8c46c Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 4 Feb 2020 16:36:59 +0100 Subject: [PATCH] freebsd,linux: simplify uv__make_socketpair() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assume the presence of the SOCK_CLOEXEC flag. It was added in FreeBSD 10 and before Linux 2.6.32. PR-URL: https://github.com/libuv/libuv/pull/2665 Reviewed-By: Santiago Gimeno Reviewed-By: Saúl Ibarra Corretgé --- src/unix/internal.h | 1 - src/unix/process.c | 32 +++++++------------------------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/unix/internal.h b/src/unix/internal.h index 47f22000..23b1def3 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -290,7 +290,6 @@ int uv___stream_fd(const uv_stream_t* handle); # define UV__F_NONBLOCK 1 #endif -int uv__make_socketpair(int fds[2], int flags); int uv__make_pipe(int fds[2], int flags); #if defined(__APPLE__) diff --git a/src/unix/process.c b/src/unix/process.c index 055a2c7d..a8fd196b 100644 --- a/src/unix/process.c +++ b/src/unix/process.c @@ -112,39 +112,21 @@ static void uv__chld(uv_signal_t* handle, int signum) { } -int uv__make_socketpair(int fds[2], int flags) { -#if defined(__linux__) - static int no_cloexec; - - if (no_cloexec) - goto skip; - - if (socketpair(AF_UNIX, SOCK_STREAM | 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) +static int uv__make_socketpair(int fds[2]) { +#if defined(__FreeBSD__) || defined(__linux__) + if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fds)) return UV__ERR(errno); - no_cloexec = 1; - -skip: -#endif - + return 0; +#else if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) return UV__ERR(errno); uv__cloexec(fds[0], 1); uv__cloexec(fds[1], 1); - if (flags & UV__F_NONBLOCK) { - uv__nonblock(fds[0], 1); - uv__nonblock(fds[1], 1); - } - return 0; +#endif } @@ -200,7 +182,7 @@ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) { if (container->data.stream->type != UV_NAMED_PIPE) return UV_EINVAL; else - return uv__make_socketpair(fds, 0); + return uv__make_socketpair(fds); case UV_INHERIT_FD: case UV_INHERIT_STREAM: