From 0e186777eb5f4d0975d15a6da3de9f46f49159f8 Mon Sep 17 00:00:00 2001 From: marius Date: Tue, 11 Dec 2018 12:56:36 -0800 Subject: [PATCH] workaround for F_DUPFD_CLOEXEC on Linux kernel <2.6.24 before it existed --- src/init.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/init.c b/src/init.c index c3e4ede715b56..f814c410dc4f2 100644 --- a/src/init.c +++ b/src/init.c @@ -345,8 +345,15 @@ int uv_dup(uv_os_fd_t fd, uv_os_fd_t* dupfd) { } #else int uv_dup(uv_os_fd_t fd, uv_os_fd_t* dupfd) { +// F_DUPFD_CLOEXEC only available since Linux 2.6.24 +#ifdef F_DUPFD_CLOEXEC if ((*dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 3)) == -1) return -errno; +#else + if ((*dupfd = fcntl(fd, F_DUPFD, 3)) == -1) + return -errno; + fcntl(fd, F_SETFD, FD_CLOEXEC); +#endif return 0; } #endif