View | Details | Raw Unified | Return to bug 46425
Collapse All | Expand All

(-)a/configure.in (+3 lines)
Lines 782-787 if test "$apr_cv_epoll" = "yes"; then Link Here
782
   AC_DEFINE([HAVE_EPOLL], 1, [Define if the epoll interface is supported])
782
   AC_DEFINE([HAVE_EPOLL], 1, [Define if the epoll interface is supported])
783
fi
783
fi
784
784
785
dnl ----------------------------- Checking for extended file descriptor handling
786
AC_CHECK_FUNCS(dup3 accept4 epoll_create1)
787
785
dnl ----------------------------- Checking for missing POSIX thread functions
788
dnl ----------------------------- Checking for missing POSIX thread functions
786
AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r])
789
AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r])
787
790
(-)a/file_io/netware/mktemp.c (-1 / +4 lines)
Lines 43-51 APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *template, apr_i Link Here
43
43
44
44
45
	if (!(flags & APR_FILE_NOCLEANUP)) {
45
	if (!(flags & APR_FILE_NOCLEANUP)) {
46
            int fdflags = fcntl(fd, F_GETFD);
47
            fdflags |= FD_CLOEXEC;
48
            fcntl(fd, F_SETFD, fdflags);
46
	    apr_pool_cleanup_register((*fp)->pool, (void *)(*fp),
49
	    apr_pool_cleanup_register((*fp)->pool, (void *)(*fp),
47
				      apr_unix_file_cleanup,
50
				      apr_unix_file_cleanup,
48
				      apr_unix_child_file_cleanup);
51
				      apr_pool_cleanup_null);
49
	}
52
	}
50
    }
53
    }
51
54
(-)a/file_io/unix/filedup.c (-7 / +18 lines)
Lines 24-37 static apr_status_t file_dup(apr_file_t **new_file, Link Here
24
                             apr_file_t *old_file, apr_pool_t *p,
24
                             apr_file_t *old_file, apr_pool_t *p,
25
                             int which_dup)
25
                             int which_dup)
26
{
26
{
27
    int rv;
27
    int rv, flags = 0;
28
    
28
    
29
    if (which_dup == 2) {
29
    if (which_dup == 2) {
30
        if ((*new_file) == NULL) {
30
        if ((*new_file) == NULL) {
31
            /* We can't dup2 unless we have a valid new_file */
31
            /* We can't dup2 unless we have a valid new_file */
32
            return APR_EINVAL;
32
            return APR_EINVAL;
33
        }
33
        }
34
#ifdef HAVE_DUP3
35
        if (!(old_file->flags & APR_INHERIT))
36
            flags |= O_CLOEXEC;
37
        rv = dup3(old_file->filedes, (*new_file)->filedes, flags);
38
#else
34
        rv = dup2(old_file->filedes, (*new_file)->filedes);
39
        rv = dup2(old_file->filedes, (*new_file)->filedes);
40
        if (!(old_file->flags & APR_INHERIT)) {
41
            flags = fcntl((*new_file)->filedes, F_GETFD);
42
            if (flags == -1)
43
                return errno;
44
            flags |= FD_CLOEXEC;
45
            if (fcntl((*new_file)->filedes, F_SETFD, flags) == -1)
46
                return errno;
47
        }
48
#endif
35
    } else {
49
    } else {
36
        rv = dup(old_file->filedes);
50
        rv = dup(old_file->filedes);
37
    }
51
    }
Lines 78-86 static apr_status_t file_dup(apr_file_t **new_file, Link Here
78
     * already closed with apr_file_close, because the expected
92
     * already closed with apr_file_close, because the expected
79
     * cleanup was already killed.
93
     * cleanup was already killed.
80
     */
94
     */
81
    if (which_dup == 2) {
95
    if (which_dup == 2)
82
        return APR_SUCCESS;
96
        return APR_SUCCESS;
83
    }
84
97
85
    /* apr_file_dup() retains all old_file flags with the exceptions
98
    /* apr_file_dup() retains all old_file flags with the exceptions
86
     * of APR_INHERIT and APR_FILE_NOCLEANUP.
99
     * of APR_INHERIT and APR_FILE_NOCLEANUP.
Lines 92-98 static apr_status_t file_dup(apr_file_t **new_file, Link Here
92
105
93
    apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file),
106
    apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file),
94
                              apr_unix_file_cleanup, 
107
                              apr_unix_file_cleanup, 
95
                              apr_unix_child_file_cleanup);
108
                              apr_pool_cleanup_null);
96
#ifndef WAITIO_USES_POLL
109
#ifndef WAITIO_USES_POLL
97
    /* Start out with no pollset.  apr_wait_for_io_or_timeout() will
110
    /* Start out with no pollset.  apr_wait_for_io_or_timeout() will
98
     * initialize the pollset if needed.
111
     * initialize the pollset if needed.
Lines 144-152 APR_DECLARE(apr_status_t) apr_file_setaside(apr_file_t **new_file, Link Here
144
    if (!(old_file->flags & APR_FILE_NOCLEANUP)) {
157
    if (!(old_file->flags & APR_FILE_NOCLEANUP)) {
145
        apr_pool_cleanup_register(p, (void *)(*new_file), 
158
        apr_pool_cleanup_register(p, (void *)(*new_file), 
146
                                  apr_unix_file_cleanup,
159
                                  apr_unix_file_cleanup,
147
                                  ((*new_file)->flags & APR_INHERIT)
160
                                  apr_pool_cleanup_null);
148
                                     ? apr_pool_cleanup_null
149
                                     : apr_unix_child_file_cleanup);
150
    }
161
    }
151
162
152
    old_file->filedes = -1;
163
    old_file->filedes = -1;
(-)a/file_io/unix/mktemp.c (-1 / +4 lines)
Lines 203-211 APR_DECLARE(apr_status_t) apr_file_mktemp(apr_file_t **fp, char *template, apr_i Link Here
203
    (*fp)->fname = apr_pstrdup(p, template);
203
    (*fp)->fname = apr_pstrdup(p, template);
204
204
205
    if (!(flags & APR_FILE_NOCLEANUP)) {
205
    if (!(flags & APR_FILE_NOCLEANUP)) {
206
        int fdflags = fcntl(fd, F_GETFD);
207
        fdflags |= FD_CLOEXEC;
208
        fcntl(fd, F_SETFD, fdflags);
206
        apr_pool_cleanup_register((*fp)->pool, (void *)(*fp),
209
        apr_pool_cleanup_register((*fp)->pool, (void *)(*fp),
207
                                  apr_unix_file_cleanup,
210
                                  apr_unix_file_cleanup,
208
                                  apr_unix_child_file_cleanup);
211
                                  apr_pool_cleanup_null);
209
    }
212
    }
210
#endif
213
#endif
211
    return APR_SUCCESS;
214
    return APR_SUCCESS;
(-)a/file_io/unix/open.c (-20 / +16 lines)
Lines 127-133 APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, Link Here
127
        oflags |= O_BINARY;
127
        oflags |= O_BINARY;
128
    }
128
    }
129
#endif
129
#endif
130
    
130
131
#ifdef O_CLOEXEC
132
    /* Introduced in Linux 2.6.23. Silently ignored on earlier Linux kernels.
133
     */
134
    if (!(flag & APR_FILE_NOCLEANUP)) {
135
        oflags |= O_CLOEXEC;
136
}
137
#endif
138
 
131
#if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
139
#if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
132
    oflags |= O_LARGEFILE;
140
    oflags |= O_LARGEFILE;
133
#elif defined(O_LARGEFILE)
141
#elif defined(O_LARGEFILE)
Lines 155-160 APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, Link Here
155
    if (fd < 0) {
163
    if (fd < 0) {
156
       return errno;
164
       return errno;
157
    }
165
    }
166
    if (!(flag & APR_FILE_NOCLEANUP)) {
167
        int fdflags = fcntl(fd, F_GETFD);
168
        fdflags |= FD_CLOEXEC;
169
        fcntl(fd, F_SETFD, fdflags);
170
    }
158
171
159
    (*new) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
172
    (*new) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
160
    (*new)->pool = pool;
173
    (*new)->pool = pool;
Lines 196-202 APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, Link Here
196
    if (!(flag & APR_FILE_NOCLEANUP)) {
209
    if (!(flag & APR_FILE_NOCLEANUP)) {
197
        apr_pool_cleanup_register((*new)->pool, (void *)(*new), 
210
        apr_pool_cleanup_register((*new)->pool, (void *)(*new), 
198
                                  apr_unix_file_cleanup, 
211
                                  apr_unix_file_cleanup, 
199
                                  apr_unix_child_file_cleanup);
212
                                  apr_pool_cleanup_null);
200
    }
213
    }
201
    return APR_SUCCESS;
214
    return APR_SUCCESS;
202
}
215
}
Lines 327-350 APR_DECLARE(apr_status_t) apr_file_open_stdin(apr_file_t **thefile, Link Here
327
}
340
}
328
341
329
APR_IMPLEMENT_INHERIT_SET(file, flags, pool, apr_unix_file_cleanup)
342
APR_IMPLEMENT_INHERIT_SET(file, flags, pool, apr_unix_file_cleanup)
330
343
APR_IMPLEMENT_INHERIT_UNSET(file, flags, pool, apr_unix_file_cleanup)
331
/* We need to do this by hand instead of using APR_IMPLEMENT_INHERIT_UNSET
332
 * because the macro sets both cleanups to the same function, which is not
333
 * suitable on Unix (see PR 41119). */
334
APR_DECLARE(apr_status_t) apr_file_inherit_unset(apr_file_t *thefile)
335
{
336
    if (thefile->flags & APR_FILE_NOCLEANUP) {
337
        return APR_EINVAL;
338
    }
339
    if (thefile->flags & APR_INHERIT) {
340
        thefile->flags &= ~APR_INHERIT;
341
        apr_pool_child_cleanup_set(thefile->pool,
342
                                   (void *)thefile,
343
                                   apr_unix_file_cleanup,
344
                                   apr_unix_child_file_cleanup);
345
    }
346
    return APR_SUCCESS;
347
}
348
344
349
APR_POOL_IMPLEMENT_ACCESSOR(file)
345
APR_POOL_IMPLEMENT_ACCESSOR(file)
350
346
(-)a/include/arch/unix/apr_arch_inherit.h (-6 / +12 lines)
Lines 27-36 apr_status_t apr_##name##_inherit_set(apr_##name##_t *the##name) \ Link Here
27
    if (the##name->flag & APR_FILE_NOCLEANUP)                       \
27
    if (the##name->flag & APR_FILE_NOCLEANUP)                       \
28
        return APR_EINVAL;                                          \
28
        return APR_EINVAL;                                          \
29
    if (!(the##name->flag & APR_INHERIT)) {                         \
29
    if (!(the##name->flag & APR_INHERIT)) {                         \
30
        int flags = fcntl(the##name->name##des, F_GETFD);           \
31
        if (flags == -1)                                            \
32
            return errno;                                           \
33
        flags &= ~(FD_CLOEXEC);                                     \
34
        if (fcntl(the##name->name##des, F_SETFD, flags) == -1)      \
35
            return errno;                                           \
30
        the##name->flag |= APR_INHERIT;                             \
36
        the##name->flag |= APR_INHERIT;                             \
31
        apr_pool_child_cleanup_set(the##name->pool,                 \
32
                                   (void *)the##name,               \
33
                                   cleanup, apr_pool_cleanup_null); \
34
    }                                                               \
37
    }                                                               \
35
    return APR_SUCCESS;                                             \
38
    return APR_SUCCESS;                                             \
36
}
39
}
Lines 41-50 apr_status_t apr_##name##_inherit_unset(apr_##name##_t *the##name) \ Link Here
41
    if (the##name->flag & APR_FILE_NOCLEANUP)                       \
44
    if (the##name->flag & APR_FILE_NOCLEANUP)                       \
42
        return APR_EINVAL;                                          \
45
        return APR_EINVAL;                                          \
43
    if (the##name->flag & APR_INHERIT) {                            \
46
    if (the##name->flag & APR_INHERIT) {                            \
47
        int flags = fcntl(the##name->name##des, F_GETFD);           \
48
        if (flags == -1)                                            \
49
            return errno;                                           \
50
        flags |= FD_CLOEXEC;                                        \
51
        if (fcntl(the##name->name##des, F_SETFD, flags) == -1)      \
52
            return errno;                                           \
44
        the##name->flag &= ~APR_INHERIT;                            \
53
        the##name->flag &= ~APR_INHERIT;                            \
45
        apr_pool_child_cleanup_set(the##name->pool,                 \
46
                                   (void *)the##name,               \
47
                                   cleanup, cleanup);               \
48
    }                                                               \
54
    }                                                               \
49
    return APR_SUCCESS;                                             \
55
    return APR_SUCCESS;                                             \
50
}
56
}
(-)a/network_io/unix/sockets.c (-7 / +31 lines)
Lines 108-116 apr_status_t apr_socket_protocol_get(apr_socket_t *sock, int *protocol) Link Here
108
apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
108
apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
109
                               int protocol, apr_pool_t *cont)
109
                               int protocol, apr_pool_t *cont)
110
{
110
{
111
    int family = ofamily;
111
    int family = ofamily, flags = 0;
112
    int oprotocol = protocol;
112
    int oprotocol = protocol;
113
113
114
#ifdef SOCK_CLOEXEC
115
    flags |= SOCK_CLOEXEC;
116
#endif
117
114
    if (family == APR_UNSPEC) {
118
    if (family == APR_UNSPEC) {
115
#if APR_HAVE_IPV6
119
#if APR_HAVE_IPV6
116
        family = APR_INET6;
120
        family = APR_INET6;
Lines 126-144 apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type, Link Here
126
    alloc_socket(new, cont);
130
    alloc_socket(new, cont);
127
131
128
#ifndef BEOS_R5
132
#ifndef BEOS_R5
129
    (*new)->socketdes = socket(family, type, protocol);
133
    (*new)->socketdes = socket(family, type|flags, protocol);
130
#else
134
#else
131
    /* For some reason BeOS R5 has an unconventional protocol numbering,
135
    /* For some reason BeOS R5 has an unconventional protocol numbering,
132
     * so we need to translate here. */
136
     * so we need to translate here. */
133
    switch (protocol) {
137
    switch (protocol) {
134
    case 0:
138
    case 0:
135
        (*new)->socketdes = socket(family, type, 0);
139
        (*new)->socketdes = socket(family, type|flags, 0);
136
        break;
140
        break;
137
    case APR_PROTO_TCP:
141
    case APR_PROTO_TCP:
138
        (*new)->socketdes = socket(family, type, IPPROTO_TCP);
142
        (*new)->socketdes = socket(family, type|flags, IPPROTO_TCP);
139
        break;
143
        break;
140
    case APR_PROTO_UDP:
144
    case APR_PROTO_UDP:
141
        (*new)->socketdes = socket(family, type, IPPROTO_UDP);
145
        (*new)->socketdes = socket(family, type|flags, IPPROTO_UDP);
142
        break;
146
        break;
143
    case APR_PROTO_SCTP:
147
    case APR_PROTO_SCTP:
144
    default:
148
    default:
Lines 151-157 apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type, Link Here
151
#if APR_HAVE_IPV6
155
#if APR_HAVE_IPV6
152
    if ((*new)->socketdes < 0 && ofamily == APR_UNSPEC) {
156
    if ((*new)->socketdes < 0 && ofamily == APR_UNSPEC) {
153
        family = APR_INET;
157
        family = APR_INET;
154
        (*new)->socketdes = socket(family, type, protocol);
158
        (*new)->socketdes = socket(family, type|flags, protocol);
155
    }
159
    }
156
#endif
160
#endif
157
161
Lines 160-165 apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type, Link Here
160
    }
164
    }
161
    set_socket_vars(*new, family, type, oprotocol);
165
    set_socket_vars(*new, family, type, oprotocol);
162
166
167
    flags = fcntl((*new)->socketdes, F_GETFD);
168
    if (flags == -1)
169
        return errno;
170
    flags |= FD_CLOEXEC;
171
    if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
172
        return errno;
173
163
    (*new)->timeout = -1;
174
    (*new)->timeout = -1;
164
    (*new)->inherit = 0;
175
    (*new)->inherit = 0;
165
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
176
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
Lines 213-224 apr_status_t apr_socket_listen(apr_socket_t *sock, apr_int32_t backlog) Link Here
213
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
224
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
214
                               apr_pool_t *connection_context)
225
                               apr_pool_t *connection_context)
215
{
226
{
216
    int s;
227
    int s, flags;
217
    apr_sockaddr_t sa;
228
    apr_sockaddr_t sa;
218
229
219
    sa.salen = sizeof(sa.sa);
230
    sa.salen = sizeof(sa.sa);
220
231
232
#ifdef HAVE_ACCEPT4
233
    s = accept4(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen, SOCK_CLOEXEC);
234
#else
221
    s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen);
235
    s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen);
236
#endif
222
237
223
    if (s < 0) {
238
    if (s < 0) {
224
        return errno;
239
        return errno;
Lines 300-305 apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock, Link Here
300
        (*new)->local_interface_unknown = 1;
315
        (*new)->local_interface_unknown = 1;
301
    }
316
    }
302
317
318
#ifndef HAVE_ACCEPT4
319
    flags = fcntl((*new)->socketdes, F_GETFD);
320
    if (flags == -1)
321
        return errno;
322
    flags |= FD_CLOEXEC;
323
    if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
324
        return errno;
325
#endif
326
303
    (*new)->inherit = 0;
327
    (*new)->inherit = 0;
304
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
328
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
305
                              socket_cleanup);
329
                              socket_cleanup);
(-)a/poll/unix/epoll.c (-3 / +23 lines)
Lines 93-106 static apr_status_t impl_pollset_create(apr_pollset_t *pollset, Link Here
93
                                        apr_uint32_t flags)
93
                                        apr_uint32_t flags)
94
{
94
{
95
    apr_status_t rv;
95
    apr_status_t rv;
96
    int fd;
96
    int fd, fdflags;
97
97
98
#ifdef HAVE_EPOLL_CREATE1
99
    fd = epoll_create1(EPOLL_CLOEXEC);
100
#else
98
    fd = epoll_create(size);
101
    fd = epoll_create(size);
102
#endif
99
    if (fd < 0) {
103
    if (fd < 0) {
100
        pollset->p = NULL;
104
        pollset->p = NULL;
101
        return apr_get_netos_error();
105
        return apr_get_netos_error();
102
    }
106
    }
103
107
108
#ifndef HAVE_EPOLL_CREATE1
109
    fdflags = fcntl(fd, F_GETFD);
110
    fdflags |= FD_CLOEXEC;
111
    fcntl(fd, F_SETFD, fdflags);
112
#endif
113
104
    pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t));
114
    pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t));
105
#if APR_HAS_THREADS
115
#if APR_HAS_THREADS
106
    if ((flags & APR_POLLSET_THREADSAFE) &&
116
    if ((flags & APR_POLLSET_THREADSAFE) &&
Lines 317-333 static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb, Link Here
317
                                       apr_pool_t *p,
327
                                       apr_pool_t *p,
318
                                       apr_uint32_t flags)
328
                                       apr_uint32_t flags)
319
{
329
{
320
    int fd;
330
    int fd, fdflags;
321
    
331
    
332
#ifdef HAVE_EPOLL_CREATE1
333
    fd = epoll_create1(EPOLL_CLOEXEC);
334
#else
322
    fd = epoll_create(size);
335
    fd = epoll_create(size);
336
#endif
323
    
337
    
324
    if (fd < 0) {
338
    if (fd < 0) {
325
        return apr_get_netos_error();
339
        return apr_get_netos_error();
326
    }
340
    }
341
342
#ifndef HAVE_EPOLL_CREATE1
343
    fdflags = fcntl(fd, F_GETFD);
344
    fdflags |= FD_CLOEXEC;
345
    fcntl(fd, F_SETFD, fdflags);
346
#endif
327
    
347
    
328
    pollcb->fd = fd;
348
    pollcb->fd = fd;
329
    pollcb->pollset.epoll = apr_palloc(p, size * sizeof(struct epoll_event));
349
    pollcb->pollset.epoll = apr_palloc(p, size * sizeof(struct epoll_event));
330
    apr_pool_cleanup_register(p, pollcb, cb_cleanup, cb_cleanup);
350
    apr_pool_cleanup_register(p, pollcb, cb_cleanup, apr_pool_cleanup_null);
331
351
332
    return APR_SUCCESS;
352
    return APR_SUCCESS;
333
}
353
}
(-)a/poll/unix/kqueue.c (-2 / +11 lines)
Lines 71-76 static apr_status_t impl_pollset_create(apr_pollset_t *pollset, Link Here
71
                                        apr_uint32_t flags)
71
                                        apr_uint32_t flags)
72
{
72
{
73
    apr_status_t rv = APR_SUCCESS;
73
    apr_status_t rv = APR_SUCCESS;
74
    int fdflags;
74
    pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t));
75
    pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t));
75
#if APR_HAS_THREADS
76
#if APR_HAS_THREADS
76
    if (flags & APR_POLLSET_THREADSAFE &&
77
    if (flags & APR_POLLSET_THREADSAFE &&
Lines 98-103 static apr_status_t impl_pollset_create(apr_pollset_t *pollset, Link Here
98
        return apr_get_netos_error();
99
        return apr_get_netos_error();
99
    }
100
    }
100
101
102
    fdflags = fcntl((*pollset)->kqueue_fd, F_GETFD);
103
    fdflags |= FD_CLOEXEC;
104
    fcntl((*pollset)->kqueue_fd, F_SETFD, fdflags);
105
101
    pollset->p->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
106
    pollset->p->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
102
107
103
    APR_RING_INIT(&pollset->p->query_ring, pfd_elem_t, link);
108
    APR_RING_INIT(&pollset->p->query_ring, pfd_elem_t, link);
Lines 306-321 static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb, Link Here
306
                                       apr_pool_t *p,
311
                                       apr_pool_t *p,
307
                                       apr_uint32_t flags)
312
                                       apr_uint32_t flags)
308
{
313
{
309
    int fd;
314
    int fd, fdflags;
310
    
315
    
311
    fd = kqueue();
316
    fd = kqueue();
312
    if (fd < 0) {
317
    if (fd < 0) {
313
        return apr_get_netos_error();
318
        return apr_get_netos_error();
314
    }
319
    }
320
321
    fdflags = fcntl(fd, F_GETFD);
322
    fdflags |= FD_CLOEXEC;
323
    fcntl(fd, F_SETFD, fdflags);
315
    
324
    
316
    pollcb->fd = fd;
325
    pollcb->fd = fd;
317
    pollcb->pollset.ke = (struct kevent *)apr_pcalloc(p, size * sizeof(struct kevent));
326
    pollcb->pollset.ke = (struct kevent *)apr_pcalloc(p, size * sizeof(struct kevent));
318
    apr_pool_cleanup_register(p, pollcb, cb_cleanup, cb_cleanup);
327
    apr_pool_cleanup_register(p, pollcb, cb_cleanup, apr_pool_cleanup_null);
319
    
328
    
320
    return APR_SUCCESS;
329
    return APR_SUCCESS;
321
}
330
}
(-)a/poll/unix/pollset.c (+10 lines)
Lines 79-84 static apr_status_t create_wakeup_pipe(apr_pollset_t *pollset) Link Here
79
{
79
{
80
    apr_status_t rv;
80
    apr_status_t rv;
81
    apr_pollfd_t fd;
81
    apr_pollfd_t fd;
82
    int fdflags;
82
83
83
    if ((rv = apr_file_pipe_create(&pollset->wakeup_pipe[0],
84
    if ((rv = apr_file_pipe_create(&pollset->wakeup_pipe[0],
84
                                   &pollset->wakeup_pipe[1],
85
                                   &pollset->wakeup_pipe[1],
Lines 87-92 static apr_status_t create_wakeup_pipe(apr_pollset_t *pollset) Link Here
87
    fd.reqevents = APR_POLLIN;
88
    fd.reqevents = APR_POLLIN;
88
    fd.desc_type = APR_POLL_FILE;
89
    fd.desc_type = APR_POLL_FILE;
89
    fd.desc.f = pollset->wakeup_pipe[0];
90
    fd.desc.f = pollset->wakeup_pipe[0];
91
92
    fdflags = fcntl(pollset->wakeup_pipe[0]->filedes, F_GETFD);
93
    fdflags |= FD_CLOEXEC;
94
    fcntl(pollset->wakeup_pipe[0]->filedes, F_SETFD, fdflags);
95
96
    fdflags = fcntl(pollset->wakeup_pipe[1]->filedes, F_GETFD);
97
    fdflags |= FD_CLOEXEC;
98
    fcntl(pollset->wakeup_pipe[1]->filedes, F_SETFD, fdflags);
99
90
    /* Add the pipe to the pollset
100
    /* Add the pipe to the pollset
91
     */
101
     */
92
    return apr_pollset_add(pollset, &fd);
102
    return apr_pollset_add(pollset, &fd);
(-)a/poll/unix/port.c (-1 / +11 lines)
Lines 100-105 static apr_status_t impl_pollset_create(apr_pollset_t **pollset, Link Here
100
{
100
{
101
    apr_status_t rv = APR_SUCCESS;
101
    apr_status_t rv = APR_SUCCESS;
102
    pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t));
102
    pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t));
103
    int fdflags;
103
#if APR_HAS_THREADS
104
#if APR_HAS_THREADS
104
    if (flags & APR_POLLSET_THREADSAFE &&
105
    if (flags & APR_POLLSET_THREADSAFE &&
105
        ((rv = apr_thread_mutex_create(&pollset->p->ring_lock,
106
        ((rv = apr_thread_mutex_create(&pollset->p->ring_lock,
Lines 125-130 static apr_status_t impl_pollset_create(apr_pollset_t **pollset, Link Here
125
        return APR_ENOMEM;
126
        return APR_ENOMEM;
126
    }
127
    }
127
128
129
    fdflags = fcntl(fd, F_GETFD);
130
    fdflags |= FD_CLOEXEC;
131
    fcntl(fd, F_SETFD, fdflags);
132
128
    pollset->p->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
133
    pollset->p->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t));
129
134
130
    APR_RING_INIT(&pollset->p->query_ring, pfd_elem_t, link);
135
    APR_RING_INIT(&pollset->p->query_ring, pfd_elem_t, link);
Lines 389-402 static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb, Link Here
389
                                       apr_pool_t *p,
394
                                       apr_pool_t *p,
390
                                       apr_uint32_t flags)
395
                                       apr_uint32_t flags)
391
{
396
{
397
    int fdflags;
392
    pollcb->fd = port_create();
398
    pollcb->fd = port_create();
393
399
394
    if (pollcb->fd < 0) {
400
    if (pollcb->fd < 0) {
395
        return apr_get_netos_error();
401
        return apr_get_netos_error();
396
    }
402
    }
397
403
404
    fdflags = fcntl(fd, F_GETFD);
405
    fdflags |= FD_CLOEXEC;
406
    fcntl(fd, F_SETFD, fdflags);
407
398
    pollcb->pollset.port = apr_palloc(p, size * sizeof(port_event_t));
408
    pollcb->pollset.port = apr_palloc(p, size * sizeof(port_event_t));
399
    apr_pool_cleanup_register(p, pollcb, cb_cleanup, cb_cleanup);
409
    apr_pool_cleanup_register(p, pollcb, cb_cleanup, apr_cleanup_null);
400
410
401
    return APR_SUCCESS;
411
    return APR_SUCCESS;
402
}
412
}

Return to bug 46425