1 Index: network_io/unix/sockets.c
2 ===================================================================
3 --- network_io/unix/sockets.c (wersja 746595)
4 +++ network_io/unix/sockets.c (kopia robocza)
6 apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
7 int protocol, apr_pool_t *cont)
9 - int family = ofamily;
10 + int family = ofamily, flags = 0;
13 + flags |= SOCK_CLOEXEC;
16 if (family == APR_UNSPEC) {
19 alloc_socket(new, cont);
22 - (*new)->socketdes = socket(family, type, protocol);
23 + (*new)->socketdes = socket(family, type|flags, protocol);
25 /* For some reason BeOS R5 has an unconventional protocol numbering,
26 * so we need to translate here. */
29 - (*new)->socketdes = socket(family, type, 0);
30 + (*new)->socketdes = socket(family, type|flags, 0);
33 - (*new)->socketdes = socket(family, type, IPPROTO_TCP);
34 + (*new)->socketdes = socket(family, type|flags, IPPROTO_TCP);
37 - (*new)->socketdes = socket(family, type, IPPROTO_UDP);
38 + (*new)->socketdes = socket(family, type|flags, IPPROTO_UDP);
44 if ((*new)->socketdes < 0 && ofamily == APR_UNSPEC) {
46 - (*new)->socketdes = socket(family, type, protocol);
47 + (*new)->socketdes = socket(family, type|flags, protocol);
53 set_socket_vars(*new, family, type, oprotocol);
56 + flags = fcntl((*new)->socketdes, F_GETFD);
59 + flags |= FD_CLOEXEC;
60 + if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
66 apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
68 apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
69 apr_pool_t *connection_context)
75 sa.salen = sizeof(sa.sa);
78 + s = accept4(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen, SOCK_CLOEXEC);
80 s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen);
86 (*new)->local_interface_unknown = 1;
90 + flags = fcntl((*new)->socketdes, F_GETFD);
93 + flags |= FD_CLOEXEC;
94 + if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
99 apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
101 Index: include/arch/unix/apr_arch_inherit.h
102 ===================================================================
103 --- include/arch/unix/apr_arch_inherit.h (wersja 746595)
104 +++ include/arch/unix/apr_arch_inherit.h (kopia robocza)
106 if (the##name->flag & APR_FILE_NOCLEANUP) \
108 if (!(the##name->flag & APR_INHERIT)) { \
109 + int flags = fcntl(the##name->name##des, F_GETFD); \
112 + flags &= ~(FD_CLOEXEC); \
113 + if (fcntl(the##name->name##des, F_SETFD, flags) == -1) \
115 the##name->flag |= APR_INHERIT; \
116 apr_pool_child_cleanup_set(the##name->pool, \
119 if (the##name->flag & APR_FILE_NOCLEANUP) \
121 if (the##name->flag & APR_INHERIT) { \
122 + int flags = fcntl(the##name->name##des, F_GETFD); \
125 + flags |= FD_CLOEXEC; \
126 + if (fcntl(the##name->name##des, F_SETFD, flags) == -1) \
128 the##name->flag &= ~APR_INHERIT; \
129 apr_pool_child_cleanup_set(the##name->pool, \
132 ===================================================================
133 --- configure.in (wersja 746595)
134 +++ configure.in (kopia robocza)
136 AC_DEFINE([HAVE_EPOLL], 1, [Define if the epoll interface is supported])
139 +dnl ----------------------------- Checking for extended file descriptor handling
140 +AC_CHECK_FUNCS(dup3 accept4 epoll_create1)
142 dnl ----------------------------- Checking for missing POSIX thread functions
143 AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r])
145 Index: poll/unix/epoll.c
146 ===================================================================
147 --- poll/unix/epoll.c (wersja 746595)
148 +++ poll/unix/epoll.c (kopia robocza)
153 +#ifdef HAVE_EPOLL_CREATE1
154 + fd = epoll_create1(EPOLL_CLOEXEC);
156 fd = epoll_create(size);
167 +#ifdef HAVE_EPOLL_CREATE1
168 + fd = epoll_create1(EPOLL_CLOEXEC);
170 fd = epoll_create(size);
174 return apr_get_netos_error();
175 Index: file_io/unix/open.c
176 ===================================================================
177 --- file_io/unix/open.c (wersja 746595)
178 +++ file_io/unix/open.c (kopia robocza)
184 + if (!(flag & APR_FILE_NOCLEANUP))
185 + oflags |= O_CLOEXEC;
188 #if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
189 oflags |= O_LARGEFILE;
193 if (thefile->flags & APR_INHERIT) {
194 + int flags = fcntl(thefile->filedes, F_GETFD);
197 + flags |= FD_CLOEXEC;
198 + if (fcntl(thefile->filedes, F_SETFD, flags) == -1)
200 thefile->flags &= ~APR_INHERIT;
201 apr_pool_child_cleanup_set(thefile->pool,
203 Index: file_io/unix/filedup.c
204 ===================================================================
205 --- file_io/unix/filedup.c (wersja 746595)
206 +++ file_io/unix/filedup.c (kopia robocza)
208 apr_file_t *old_file, apr_pool_t *p,
214 if (which_dup == 2) {
215 if ((*new_file) == NULL) {
216 /* We can't dup2 unless we have a valid new_file */
220 + if (!(old_file->flags & APR_INHERIT))
221 + flags |= O_CLOEXEC;
222 + rv = dup3(old_file->filedes, (*new_file)->filedes, flags);
224 + if (!(old_file->flags & APR_INHERIT)) {
225 + flags = fcntl(old_file->filedes, F_GETFD);
228 + flags |= FD_CLOEXEC;
229 + if (fcntl(old_file->filedes, F_SETFD, flags) == -1)
232 rv = dup2(old_file->filedes, (*new_file)->filedes);
235 rv = dup(old_file->filedes);