diff options
author | Bojan Smojver <bojan@apache.org> | 2009-06-12 03:21:22 +0000 |
---|---|---|
committer | Bojan Smojver <bojan@apache.org> | 2009-06-12 03:21:22 +0000 |
commit | d8c00503725305c6f41f6efd58c1a3dcc06d1fcd (patch) | |
tree | 77bb8b73a8798597440f7cb9bfc72c247fa9971f /poll | |
parent | ad67ed01e13eadec2f9531ec71dca8bf0ca82b9f (diff) | |
download | apr-d8c00503725305c6f41f6efd58c1a3dcc06d1fcd.tar.gz |
Backport r747990, r748361, r748371, r748565, r748988, r749810, r783958
from the trunk.
Set CLOEXEC flags where appropriate. Either use new O_CLOEXEC flag and
associated functions, such as dup3(), accept4(), epoll_create1() etc., or
simply set CLOEXEC flag using fcntl().
Patch by Stefan Fritsch <sf sfritsch.de> and
Arkadiusz Miskiewicz <arekm pld-linux.org>.
PR 46425.
fix unused variable warning for builds without HAVE_DUP3
Unroll APR_SET_FD_CLOEXEC macro.
* One missing unroll of APR_SET_FD_CLOEXEC.
Document CLOEXEC patch.
Only set CLOEXEC on dup() if both NOCLEANUP and INHERIT flags are clear.
Retain the INHERIT/NOCLEANUP flags of new_file in apr_file_dup2().
Patch by Stefan Fritsch <sf sfritsch.de>.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.4.x@783970 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poll')
-rw-r--r-- | poll/unix/epoll.c | 35 | ||||
-rw-r--r-- | poll/unix/kqueue.c | 25 | ||||
-rw-r--r-- | poll/unix/port.c | 23 |
3 files changed, 82 insertions, 1 deletions
diff --git a/poll/unix/epoll.c b/poll/unix/epoll.c index c8ab6d63a..0c5fa8f67 100644 --- a/poll/unix/epoll.c +++ b/poll/unix/epoll.c @@ -15,6 +15,7 @@ */ #include "apr_arch_poll_private.h" +#include "apr_arch_inherit.h" #ifdef POLLSET_USES_EPOLL @@ -147,12 +148,29 @@ APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, /* Add room for wakeup descriptor */ size++; } +#ifdef HAVE_EPOLL_CREATE1 + fd = epoll_create1(EPOLL_CLOEXEC); +#else fd = epoll_create(size); +#endif if (fd < 0) { *pollset = NULL; return errno; } +#ifndef HAVE_EPOLL_CREATE1 + { + int flags; + + if ((flags = fcntl(fd, F_GETFD)) == -1) + return errno; + + flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, flags) == -1) + return errno; + } +#endif + *pollset = apr_palloc(p, sizeof(**pollset)); #if APR_HAS_THREADS if ((flags & APR_POLLSET_THREADSAFE) && @@ -413,12 +431,29 @@ APR_DECLARE(apr_status_t) apr_pollcb_create(apr_pollcb_t **pollcb, { int fd; +#ifdef HAVE_EPOLL_CREATE1 + fd = epoll_create1(EPOLL_CLOEXEC); +#else fd = epoll_create(size); +#endif if (fd < 0) { *pollcb = NULL; return apr_get_netos_error(); } + +#ifndef HAVE_EPOLL_CREATE1 + { + int flags; + + if ((flags = fcntl(fd, F_GETFD)) == -1) + return errno; + + flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, flags) == -1) + return errno; + } +#endif *pollcb = apr_palloc(p, sizeof(**pollcb)); (*pollcb)->nalloc = size; diff --git a/poll/unix/kqueue.c b/poll/unix/kqueue.c index 406eba6e9..34ec1dd42 100644 --- a/poll/unix/kqueue.c +++ b/poll/unix/kqueue.c @@ -15,6 +15,7 @@ */ #include "apr_arch_poll_private.h" +#include "apr_arch_inherit.h" #ifdef POLLSET_USES_KQUEUE @@ -156,6 +157,17 @@ APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, return apr_get_netos_error(); } + { + int flags; + + if ((flags = fcntl((*pollset)->kqueue_fd, F_GETFD)) == -1) + return errno; + + flags |= FD_CLOEXEC; + if (fcntl((*pollset)->kqueue_fd, F_SETFD, flags) == -1) + return errno; + } + (*pollset)->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); APR_RING_INIT(&(*pollset)->query_ring, pfd_elem_t, link); @@ -389,7 +401,18 @@ APR_DECLARE(apr_status_t) apr_pollcb_create(apr_pollcb_t **pollcb, *pollcb = NULL; return apr_get_netos_error(); } - + + { + int flags; + + if ((flags = fcntl(fd, F_GETFD)) == -1) + return errno; + + flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, flags) == -1) + return errno; + } + *pollcb = apr_palloc(p, sizeof(**pollcb)); (*pollcb)->nalloc = size; (*pollcb)->pool = p; diff --git a/poll/unix/port.c b/poll/unix/port.c index 73d852511..ab45b9913 100644 --- a/poll/unix/port.c +++ b/poll/unix/port.c @@ -16,6 +16,7 @@ #include "apr_arch_poll_private.h" #include "apr_atomic.h" +#include "apr_arch_inherit.h" #ifdef POLLSET_USES_PORT @@ -181,6 +182,17 @@ APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, return APR_ENOMEM; } + { + int flags; + + if ((flags = fcntl((*pollset)->port_fd, F_GETFD)) == -1) + return errno; + + flags |= FD_CLOEXEC; + if (fcntl((*pollset)->port_fd, F_SETFD, flags) == -1) + return errno; + } + (*pollset)->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); APR_RING_INIT(&(*pollset)->query_ring, pfd_elem_t, link); @@ -474,6 +486,17 @@ APR_DECLARE(apr_status_t) apr_pollcb_create(apr_pollcb_t **pollcb, return apr_get_netos_error(); } + { + int flags; + + if ((flags = fcntl(fd, F_GETFD)) == -1) + return errno; + + flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, flags) == -1) + return errno; + } + *pollcb = apr_palloc(p, sizeof(**pollcb)); (*pollcb)->nalloc = size; (*pollcb)->pool = p; |