1 diff -ur apr-1.3.3.org/configure.in apr-1.3.3/configure.in
2 --- apr-1.3.3.org/configure.in 2009-02-22 15:55:36.340196167 +0100
3 +++ apr-1.3.3/configure.in 2009-02-22 15:56:09.198943991 +0100
5 AC_DEFINE([HAVE_EPOLL], 1, [Define if the epoll interface is supported])
8 +dnl ----------------------------- Checking for extended file descriptor handling
9 +AC_CHECK_FUNCS(dup3 accept4 epoll_create1)
11 dnl ----------------------------- Checking for missing POSIX thread functions
12 AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r])
14 diff -ur apr-1.3.3.org/file_io/netware/mktemp.c apr-1.3.3/file_io/netware/mktemp.c
15 --- apr-1.3.3.org/file_io/netware/mktemp.c 2007-06-01 19:58:04.000000000 +0200
16 +++ apr-1.3.3/file_io/netware/mktemp.c 2009-02-22 15:56:09.402572969 +0100
20 if (!(flags & APR_FILE_NOCLEANUP)) {
21 + int fdflags = fcntl(fd, F_GETFD);
22 + fdflags |= FD_CLOEXEC;
23 + fcntl(fd, F_SETFD, fdflags);
24 apr_pool_cleanup_register((*fp)->pool, (void *)(*fp),
25 apr_unix_file_cleanup,
26 - apr_unix_child_file_cleanup);
27 + apr_pool_cleanup_null);
31 diff -ur apr-1.3.3.org/file_io/unix/filedup.c apr-1.3.3/file_io/unix/filedup.c
32 --- apr-1.3.3.org/file_io/unix/filedup.c 2007-05-15 04:37:16.000000000 +0200
33 +++ apr-1.3.3/file_io/unix/filedup.c 2009-02-22 15:56:09.402572969 +0100
35 apr_file_t *old_file, apr_pool_t *p,
42 if ((*new_file) == NULL) {
43 /* We can't dup2 unless we have a valid new_file */
47 + if (!(old_file->flags & APR_INHERIT))
49 + rv = dup3(old_file->filedes, (*new_file)->filedes, flags);
51 rv = dup2(old_file->filedes, (*new_file)->filedes);
52 + if (!(old_file->flags & APR_INHERIT)) {
53 + flags = fcntl((*new_file)->filedes, F_GETFD);
56 + flags |= FD_CLOEXEC;
57 + if (fcntl((*new_file)->filedes, F_SETFD, flags) == -1)
62 rv = dup(old_file->filedes);
65 * already closed with apr_file_close, because the expected
66 * cleanup was already killed.
68 - if (which_dup == 2) {
73 /* apr_file_dup() retains all old_file flags with the exceptions
74 * of APR_INHERIT and APR_FILE_NOCLEANUP.
77 apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file),
78 apr_unix_file_cleanup,
79 - apr_unix_child_file_cleanup);
80 + apr_pool_cleanup_null);
81 #ifndef WAITIO_USES_POLL
82 /* Start out with no pollset. apr_wait_for_io_or_timeout() will
83 * initialize the pollset if needed.
85 if (!(old_file->flags & APR_FILE_NOCLEANUP)) {
86 apr_pool_cleanup_register(p, (void *)(*new_file),
87 apr_unix_file_cleanup,
88 - ((*new_file)->flags & APR_INHERIT)
89 - ? apr_pool_cleanup_null
90 - : apr_unix_child_file_cleanup);
91 + apr_pool_cleanup_null);
94 old_file->filedes = -1;
95 diff -ur apr-1.3.3.org/file_io/unix/mktemp.c apr-1.3.3/file_io/unix/mktemp.c
96 --- apr-1.3.3.org/file_io/unix/mktemp.c 2007-06-01 19:58:04.000000000 +0200
97 +++ apr-1.3.3/file_io/unix/mktemp.c 2009-02-22 15:56:09.402572969 +0100
99 (*fp)->fname = apr_pstrdup(p, template);
101 if (!(flags & APR_FILE_NOCLEANUP)) {
102 + int fdflags = fcntl(fd, F_GETFD);
103 + fdflags |= FD_CLOEXEC;
104 + fcntl(fd, F_SETFD, fdflags);
105 apr_pool_cleanup_register((*fp)->pool, (void *)(*fp),
106 apr_unix_file_cleanup,
107 - apr_unix_child_file_cleanup);
108 + apr_pool_cleanup_null);
112 diff -ur apr-1.3.3.org/file_io/unix/open.c apr-1.3.3/file_io/unix/open.c
113 --- apr-1.3.3.org/file_io/unix/open.c 2007-05-15 04:37:16.000000000 +0200
114 +++ apr-1.3.3/file_io/unix/open.c 2009-02-22 15:56:09.402572969 +0100
122 + /* Introduced in Linux 2.6.23. Silently ignored on earlier Linux kernels.
124 + if (!(flag & APR_FILE_NOCLEANUP)) {
125 + oflags |= O_CLOEXEC;
129 #if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
130 oflags |= O_LARGEFILE;
131 #elif defined(O_LARGEFILE)
136 + if (!(flag & APR_FILE_NOCLEANUP)) {
137 + int fdflags = fcntl(fd, F_GETFD);
138 + fdflags |= FD_CLOEXEC;
139 + fcntl(fd, F_SETFD, fdflags);
142 (*new) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
145 if (!(flag & APR_FILE_NOCLEANUP)) {
146 apr_pool_cleanup_register((*new)->pool, (void *)(*new),
147 apr_unix_file_cleanup,
148 - apr_unix_child_file_cleanup);
149 + apr_pool_cleanup_null);
156 APR_IMPLEMENT_INHERIT_SET(file, flags, pool, apr_unix_file_cleanup)
158 -/* We need to do this by hand instead of using APR_IMPLEMENT_INHERIT_UNSET
159 - * because the macro sets both cleanups to the same function, which is not
160 - * suitable on Unix (see PR 41119). */
161 -APR_DECLARE(apr_status_t) apr_file_inherit_unset(apr_file_t *thefile)
163 - if (thefile->flags & APR_FILE_NOCLEANUP) {
166 - if (thefile->flags & APR_INHERIT) {
167 - thefile->flags &= ~APR_INHERIT;
168 - apr_pool_child_cleanup_set(thefile->pool,
170 - apr_unix_file_cleanup,
171 - apr_unix_child_file_cleanup);
173 - return APR_SUCCESS;
175 +APR_IMPLEMENT_INHERIT_UNSET(file, flags, pool, apr_unix_file_cleanup)
177 APR_POOL_IMPLEMENT_ACCESSOR(file)
178 Tylko w apr-1.3.3/file_io/unix: open.c.orig
179 diff -ur apr-1.3.3.org/include/arch/unix/apr_arch_inherit.h apr-1.3.3/include/arch/unix/apr_arch_inherit.h
180 --- apr-1.3.3.org/include/arch/unix/apr_arch_inherit.h 2006-08-03 12:55:31.000000000 +0200
181 +++ apr-1.3.3/include/arch/unix/apr_arch_inherit.h 2009-02-22 15:56:09.402572969 +0100
183 if (the##name->flag & APR_FILE_NOCLEANUP) \
185 if (!(the##name->flag & APR_INHERIT)) { \
186 + int flags = fcntl(the##name->name##des, F_GETFD); \
189 + flags &= ~(FD_CLOEXEC); \
190 + if (fcntl(the##name->name##des, F_SETFD, flags) == -1) \
192 the##name->flag |= APR_INHERIT; \
193 - apr_pool_child_cleanup_set(the##name->pool, \
194 - (void *)the##name, \
195 - cleanup, apr_pool_cleanup_null); \
197 return APR_SUCCESS; \
200 if (the##name->flag & APR_FILE_NOCLEANUP) \
202 if (the##name->flag & APR_INHERIT) { \
203 + int flags = fcntl(the##name->name##des, F_GETFD); \
206 + flags |= FD_CLOEXEC; \
207 + if (fcntl(the##name->name##des, F_SETFD, flags) == -1) \
209 the##name->flag &= ~APR_INHERIT; \
210 - apr_pool_child_cleanup_set(the##name->pool, \
211 - (void *)the##name, \
212 - cleanup, cleanup); \
214 return APR_SUCCESS; \
216 diff -ur apr-1.3.3.org/network_io/unix/sockets.c apr-1.3.3/network_io/unix/sockets.c
217 --- apr-1.3.3.org/network_io/unix/sockets.c 2009-02-22 15:55:36.179428770 +0100
218 +++ apr-1.3.3/network_io/unix/sockets.c 2009-02-22 16:09:42.820111487 +0100
220 apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
221 int protocol, apr_pool_t *cont)
223 - int family = ofamily;
224 + int family = ofamily, flags = 0;
227 + flags |= SOCK_CLOEXEC;
230 if (family == APR_UNSPEC) {
233 alloc_socket(new, cont);
236 - (*new)->socketdes = socket(family, type, protocol);
237 + (*new)->socketdes = socket(family, type|flags, protocol);
239 /* For some reason BeOS R5 has an unconventional protocol numbering,
240 * so we need to translate here. */
243 - (*new)->socketdes = socket(family, type, 0);
244 + (*new)->socketdes = socket(family, type|flags, 0);
247 - (*new)->socketdes = socket(family, type, IPPROTO_TCP);
248 + (*new)->socketdes = socket(family, type|flags, IPPROTO_TCP);
251 - (*new)->socketdes = socket(family, type, IPPROTO_UDP);
252 + (*new)->socketdes = socket(family, type|flags, IPPROTO_UDP);
258 if ((*new)->socketdes < 0 && ofamily == APR_UNSPEC) {
260 - (*new)->socketdes = socket(family, type, protocol);
261 + (*new)->socketdes = socket(family, type|flags, protocol);
267 set_socket_vars(*new, family, type, protocol);
269 +#ifndef SOCK_CLOEXEC
270 + flags = fcntl((*new)->socketdes, F_GETFD);
273 + flags |= FD_CLOEXEC;
274 + if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
278 (*new)->timeout = -1;
280 apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
281 @@ -176,12 +189,16 @@
282 apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
283 apr_pool_t *connection_context)
289 sa.salen = sizeof(sa.sa);
292 + s = accept4(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen, SOCK_CLOEXEC);
294 s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen);
300 (*new)->local_interface_unknown = 1;
303 +#ifndef HAVE_ACCEPT4
304 + flags = fcntl((*new)->socketdes, F_GETFD);
307 + flags |= FD_CLOEXEC;
308 + if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
313 apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
315 diff -ur apr-1.3.3.org/poll/unix/epoll.c apr-1.3.3/poll/unix/epoll.c
316 --- apr-1.3.3.org/poll/unix/epoll.c 2008-04-13 13:37:52.000000000 +0200
317 +++ apr-1.3.3/poll/unix/epoll.c 2009-02-22 16:01:22.005735200 +0100
325 +#ifdef HAVE_EPOLL_CREATE1
326 + fd = epoll_create1(EPOLL_CLOEXEC);
328 fd = epoll_create(size);
335 +#ifndef HAVE_EPOLL_CREATE1
336 + fdflags = fcntl(fd, F_GETFD);
337 + fdflags |= FD_CLOEXEC;
338 + fcntl(fd, F_SETFD, fdflags);
341 *pollset = apr_palloc(p, sizeof(**pollset));
343 if ((flags & APR_POLLSET_THREADSAFE) &&
344 @@ -315,14 +325,24 @@
352 +#ifdef HAVE_EPOLL_CREATE1
353 + fd = epoll_create1(EPOLL_CLOEXEC);
355 fd = epoll_create(size);
360 return apr_get_netos_error();
363 +#ifndef HAVE_EPOLL_CREATE1
364 + fdflags = fcntl(fd, F_GETFD);
365 + fdflags |= FD_CLOEXEC;
366 + fcntl(fd, F_SETFD, fdflags);
369 *pollcb = apr_palloc(p, sizeof(**pollcb));
370 (*pollcb)->nalloc = size;