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

(-)a/file_io/unix/filedup.c (+8 lines)
Lines 79-84 static apr_status_t file_dup(apr_file_t **new_file, Link Here
79
     * cleanup was already killed.
79
     * cleanup was already killed.
80
     */
80
     */
81
    if (which_dup == 2) {
81
    if (which_dup == 2) {
82
        if (!(old_file->flags & APR_INHERIT)) {
83
            /* Since dup2 does not retain the FD_CLOEXEC flag, we have to set it
84
             * explicitly when necessary.
85
             */
86
            int flags = fcntl((*new_file)->filedes, F_GETFD);
87
            flags |= FD_CLOEXEC;
88
            fcntl((*new_file)->filedes, F_SETFD, flags);
89
        }
82
        return APR_SUCCESS;
90
        return APR_SUCCESS;
83
    }
91
    }
84
92
(-)a/file_io/unix/open.c (+9 lines)
Lines 155-160 APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, Link Here
155
    if (fd < 0) {
155
    if (fd < 0) {
156
       return errno;
156
       return errno;
157
    }
157
    }
158
    if (!(flag & APR_FILE_NOCLEANUP)) {
159
        int fdflags = fcntl(fd, F_GETFD);
160
        fdflags |= FD_CLOEXEC;
161
        fcntl(fd, F_SETFD, fdflags);
162
    }
158
163
159
    (*new) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
164
    (*new) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
160
    (*new)->pool = pool;
165
    (*new)->pool = pool;
Lines 337-342 APR_DECLARE(apr_status_t) apr_file_inherit_unset(apr_file_t *thefile) Link Here
337
        return APR_EINVAL;
342
        return APR_EINVAL;
338
    }
343
    }
339
    if (thefile->flags & APR_INHERIT) {
344
    if (thefile->flags & APR_INHERIT) {
345
        int flags = fcntl(thefile->filedes, F_GETFD);
346
        flags |= FD_CLOEXEC;
347
        fcntl(thefile->filedes, F_SETFD, flags);
348
340
        thefile->flags &= ~APR_INHERIT;
349
        thefile->flags &= ~APR_INHERIT;
341
        apr_pool_child_cleanup_set(thefile->pool,
350
        apr_pool_child_cleanup_set(thefile->pool,
342
                                   (void *)thefile,
351
                                   (void *)thefile,
(-)a/include/arch/unix/apr_arch_inherit.h (+6 lines)
Lines 27-32 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
        flags &= ~(FD_CLOEXEC);                                     \
32
        fcntl(the##name->name##des, F_SETFD, flags);                  \
30
        the##name->flag |= APR_INHERIT;                             \
33
        the##name->flag |= APR_INHERIT;                             \
31
        apr_pool_child_cleanup_set(the##name->pool,                 \
34
        apr_pool_child_cleanup_set(the##name->pool,                 \
32
                                   (void *)the##name,               \
35
                                   (void *)the##name,               \
Lines 41-46 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
        flags |= FD_CLOEXEC;                                        \
49
        fcntl(the##name->name##des, F_SETFD, flags);                  \
44
        the##name->flag &= ~APR_INHERIT;                            \
50
        the##name->flag &= ~APR_INHERIT;                            \
45
        apr_pool_child_cleanup_set(the##name->pool,                 \
51
        apr_pool_child_cleanup_set(the##name->pool,                 \
46
                                   (void *)the##name,               \
52
                                   (void *)the##name,               \
(-)a/network_io/unix/sockets.c (-2 / +10 lines)
Lines 83-89 apr_status_t apr_socket_protocol_get(apr_socket_t *sock, int *protocol) Link Here
83
apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
83
apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
84
                               int protocol, apr_pool_t *cont)
84
                               int protocol, apr_pool_t *cont)
85
{
85
{
86
    int family = ofamily;
86
    int flags, family = ofamily;
87
87
88
    if (family == APR_UNSPEC) {
88
    if (family == APR_UNSPEC) {
89
#if APR_HAVE_IPV6
89
#if APR_HAVE_IPV6
Lines 130-135 apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type, Link Here
130
    }
130
    }
131
    set_socket_vars(*new, family, type, protocol);
131
    set_socket_vars(*new, family, type, protocol);
132
132
133
    flags = fcntl((*new)->socketdes, F_GETFD);
134
    flags |= FD_CLOEXEC;
135
    fcntl((*new)->socketdes, F_SETFD, flags);
136
133
    (*new)->timeout = -1;
137
    (*new)->timeout = -1;
134
    (*new)->inherit = 0;
138
    (*new)->inherit = 0;
135
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
139
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
Lines 176-182 apr_status_t apr_socket_listen(apr_socket_t *sock, apr_int32_t backlog) Link Here
176
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
180
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
177
                               apr_pool_t *connection_context)
181
                               apr_pool_t *connection_context)
178
{
182
{
179
    int s;
183
    int s, flags;
180
    apr_sockaddr_t sa;
184
    apr_sockaddr_t sa;
181
185
182
    sa.salen = sizeof(sa.sa);
186
    sa.salen = sizeof(sa.sa);
Lines 255-260 apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock, Link Here
255
        (*new)->local_interface_unknown = 1;
259
        (*new)->local_interface_unknown = 1;
256
    }
260
    }
257
261
262
    flags = fcntl((*new)->socketdes, F_GETFD);
263
    flags |= FD_CLOEXEC;
264
    fcntl((*new)->socketdes, F_SETFD, flags);
265
258
    (*new)->inherit = 0;
266
    (*new)->inherit = 0;
259
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
267
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
260
                              socket_cleanup);
268
                              socket_cleanup);
(-)a/poll/unix/epoll.c (-2 / +10 lines)
Lines 141-147 APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, Link Here
141
                                             apr_uint32_t flags)
141
                                             apr_uint32_t flags)
142
{
142
{
143
    apr_status_t rv;
143
    apr_status_t rv;
144
    int fd;
144
    int fd, fdflags;
145
145
146
    if (flags & APR_POLLSET_WAKEABLE) {
146
    if (flags & APR_POLLSET_WAKEABLE) {
147
        /* Add room for wakeup descriptor */
147
        /* Add room for wakeup descriptor */
Lines 153-158 APR_DECLARE(apr_status_t) apr_pollset_create(apr_pollset_t **pollset, Link Here
153
        return errno;
153
        return errno;
154
    }
154
    }
155
155
156
    fdflags = fcntl(fd, F_GETFD);
157
    fdflags |= FD_CLOEXEC;
158
    fcntl(fd, F_SETFD, fdflags);
159
156
    *pollset = apr_palloc(p, sizeof(**pollset));
160
    *pollset = apr_palloc(p, sizeof(**pollset));
157
#if APR_HAS_THREADS
161
#if APR_HAS_THREADS
158
    if ((flags & APR_POLLSET_THREADSAFE) &&
162
    if ((flags & APR_POLLSET_THREADSAFE) &&
Lines 411-417 APR_DECLARE(apr_status_t) apr_pollcb_create(apr_pollcb_t **pollcb, Link Here
411
                                            apr_pool_t *p,
415
                                            apr_pool_t *p,
412
                                            apr_uint32_t flags)
416
                                            apr_uint32_t flags)
413
{
417
{
414
    int fd;
418
    int fd, fdflags;
415
    
419
    
416
    fd = epoll_create(size);
420
    fd = epoll_create(size);
417
    
421
    
Lines 419-424 APR_DECLARE(apr_status_t) apr_pollcb_create(apr_pollcb_t **pollcb, Link Here
419
        *pollcb = NULL;
423
        *pollcb = NULL;
420
        return apr_get_netos_error();
424
        return apr_get_netos_error();
421
    }
425
    }
426
427
    fdflags = fcntl(fd, F_GETFD);
428
    fdflags |= FD_CLOEXEC;
429
    fcntl(fd, F_SETFD, fdflags);
422
    
430
    
423
    *pollcb = apr_palloc(p, sizeof(**pollcb));
431
    *pollcb = apr_palloc(p, sizeof(**pollcb));
424
    (*pollcb)->nalloc = size;
432
    (*pollcb)->nalloc = size;

Return to bug 46425