1 diff -urN apr-1.3.3.org/file_io/unix/filedup.c apr-1.3.3/file_io/unix/filedup.c
2 --- apr-1.3.3.org/file_io/unix/filedup.c 2007-05-15 04:37:16.000000000 +0200
3 +++ apr-1.3.3/file_io/unix/filedup.c 2009-02-23 08:15:10.023641368 +0100
5 apr_file_t *old_file, apr_pool_t *p,
12 if ((*new_file) == NULL) {
16 rv = dup2(old_file->filedes, (*new_file)->filedes);
17 + if (!(old_file->flags & APR_INHERIT)) {
18 + fdflags = fcntl((*new_file)->filedes, F_GETFD);
21 + fdflags |= FD_CLOEXEC;
22 + if (fcntl((*new_file)->filedes, F_SETFD, fdflags) == -1)
26 rv = dup(old_file->filedes);
28 diff -urN apr-1.3.3.org/file_io/unix/mktemp.c apr-1.3.3/file_io/unix/mktemp.c
29 --- apr-1.3.3.org/file_io/unix/mktemp.c 2007-06-01 19:58:04.000000000 +0200
30 +++ apr-1.3.3/file_io/unix/mktemp.c 2009-02-23 08:18:30.420011379 +0100
32 (*fp)->fname = apr_pstrdup(p, template);
34 if (!(flags & APR_FILE_NOCLEANUP)) {
35 + int fdflags = fcntl(fd, F_GETFD);
36 + if (fdflags != -1) {
37 + fdflags |= FD_CLOEXEC;
38 + fcntl(fd, F_SETFD, fdflags);
40 apr_pool_cleanup_register((*fp)->pool, (void *)(*fp),
41 apr_unix_file_cleanup,
42 apr_unix_child_file_cleanup);
43 diff -urN apr-1.3.3.org/file_io/unix/open.c apr-1.3.3/file_io/unix/open.c
44 --- apr-1.3.3.org/file_io/unix/open.c 2007-05-15 04:37:16.000000000 +0200
45 +++ apr-1.3.3/file_io/unix/open.c 2009-02-23 08:13:44.356609676 +0100
53 + /* Introduced in Linux 2.6.23. Silently ignored on earlier Linux kernels.
55 + if (!(flag & APR_FILE_NOCLEANUP)) {
56 + oflags |= O_CLOEXEC;
60 #if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
61 oflags |= O_LARGEFILE;
62 #elif defined(O_LARGEFILE)
67 + if (!(flag & APR_FILE_NOCLEANUP)) {
68 + int fdflags = fcntl(fd, F_GETFD);
69 + fdflags |= FD_CLOEXEC;
70 + fcntl(fd, F_SETFD, fdflags);
73 (*new) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
75 diff -urN apr-1.3.3.org/include/arch/unix/apr_arch_inherit.h apr-1.3.3/include/arch/unix/apr_arch_inherit.h
76 --- apr-1.3.3.org/include/arch/unix/apr_arch_inherit.h 2006-08-03 12:55:31.000000000 +0200
77 +++ apr-1.3.3/include/arch/unix/apr_arch_inherit.h 2009-02-23 08:17:48.033064583 +0100
79 if (the##name->flag & APR_FILE_NOCLEANUP) \
81 if (!(the##name->flag & APR_INHERIT)) { \
82 + int fdflags = fcntl(the##name->name##des, F_GETFD); \
83 + if (fdflags == -1) \
85 + fdflags &= ~(FD_CLOEXEC); \
86 + if (fcntl(the##name->name##des, F_SETFD, fdflags) == -1) \
88 the##name->flag |= APR_INHERIT; \
89 apr_pool_child_cleanup_set(the##name->pool, \
92 if (the##name->flag & APR_FILE_NOCLEANUP) \
94 if (the##name->flag & APR_INHERIT) { \
95 + int fdflags = fcntl(the##name->name##des, F_GETFD); \
96 + if (fdflags == -1) \
98 + fdflags |= FD_CLOEXEC; \
99 + if (fcntl(the##name->name##des, F_SETFD, fdflags) == -1) \
101 the##name->flag &= ~APR_INHERIT; \
102 apr_pool_child_cleanup_set(the##name->pool, \
104 diff -urN apr-1.3.3.org/network_io/unix/sockets.c apr-1.3.3/network_io/unix/sockets.c
105 --- apr-1.3.3.org/network_io/unix/sockets.c 2009-02-23 08:08:40.966440943 +0100
106 +++ apr-1.3.3/network_io/unix/sockets.c 2009-02-23 08:19:02.086419869 +0100
108 apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
109 int protocol, apr_pool_t *cont)
111 - int family = ofamily;
112 + int family = ofamily, fdflags;
114 if (family == APR_UNSPEC) {
118 set_socket_vars(*new, family, type, protocol);
120 + fdflags = fcntl((*new)->socketdes, F_GETFD);
123 + fdflags |= FD_CLOEXEC;
124 + if (fcntl((*new)->socketdes, F_SETFD, fdflags) == -1)
127 (*new)->timeout = -1;
129 apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
131 apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
132 apr_pool_t *connection_context)
138 sa.salen = sizeof(sa.sa);
140 (*new)->local_interface_unknown = 1;
143 + fdflags = fcntl((*new)->socketdes, F_GETFD);
146 + fdflags |= FD_CLOEXEC;
147 + if (fcntl((*new)->socketdes, F_SETFD, fdflags) == -1)
151 apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
153 diff -urN apr-1.3.3.org/poll/unix/epoll.c apr-1.3.3/poll/unix/epoll.c
154 --- apr-1.3.3.org/poll/unix/epoll.c 2008-04-13 13:37:52.000000000 +0200
155 +++ apr-1.3.3/poll/unix/epoll.c 2009-02-23 08:20:07.663209400 +0100
163 fd = epoll_create(size);
169 + fdflags = fcntl(fd, F_GETFD);
170 + if (fdflags != -1) {
171 + fdflags |= FD_CLOEXEC;
172 + fcntl(fd, F_SETFD, fdflags);
175 *pollset = apr_palloc(p, sizeof(**pollset));
177 if ((flags & APR_POLLSET_THREADSAFE) &&
178 @@ -315,14 +321,20 @@
186 fd = epoll_create(size);
190 return apr_get_netos_error();
193 + fdflags = fcntl(fd, F_GETFD);
194 + if (fdflags != -1) {
195 + fdflags |= FD_CLOEXEC;
196 + fcntl(fd, F_SETFD, fdflags);
199 *pollcb = apr_palloc(p, sizeof(**pollcb));
200 (*pollcb)->nalloc = size;