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

(-)network_io/unix/sockets.c (-7 / +33 lines)
Lines 108-116 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;
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 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 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 Link Here
160
    }
164
    }
161
    set_socket_vars(*new, family, type, oprotocol);
165
    set_socket_vars(*new, family, type, oprotocol);
162
166
167
#ifndef SOCK_CLOEXEC
168
    flags = fcntl((*new)->socketdes, F_GETFD);
169
    if (flags == -1)
170
        return errno;
171
    flags |= FD_CLOEXEC;
172
    if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
173
        return errno;
174
#endif
175
163
    (*new)->timeout = -1;
176
    (*new)->timeout = -1;
164
    (*new)->inherit = 0;
177
    (*new)->inherit = 0;
165
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
178
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
Lines 213-224 Link Here
213
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
226
apr_status_t apr_socket_accept(apr_socket_t **new, apr_socket_t *sock,
214
                               apr_pool_t *connection_context)
227
                               apr_pool_t *connection_context)
215
{
228
{
216
    int s;
229
    int s, flags;
217
    apr_sockaddr_t sa;
230
    apr_sockaddr_t sa;
218
231
219
    sa.salen = sizeof(sa.sa);
232
    sa.salen = sizeof(sa.sa);
220
233
234
#ifdef HAVE_ACCEPT4
235
    s = accept4(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen, SOCK_CLOEXEC);
236
#else
221
    s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen);
237
    s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen);
238
#endif
222
239
223
    if (s < 0) {
240
    if (s < 0) {
224
        return errno;
241
        return errno;
Lines 300-305 Link Here
300
        (*new)->local_interface_unknown = 1;
317
        (*new)->local_interface_unknown = 1;
301
    }
318
    }
302
319
320
#ifndef HAVE_ACCEPT4
321
    flags = fcntl((*new)->socketdes, F_GETFD);
322
    if (flags == -1)
323
        return errno;
324
    flags |= FD_CLOEXEC;
325
    if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
326
        return errno;
327
#endif
328
303
    (*new)->inherit = 0;
329
    (*new)->inherit = 0;
304
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
330
    apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
305
                              socket_cleanup);
331
                              socket_cleanup);
(-)include/arch/unix/apr_arch_inherit.h (+12 lines)
Lines 27-32 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,                 \
37
        apr_pool_child_cleanup_set(the##name->pool,                 \
32
                                   (void *)the##name,               \
38
                                   (void *)the##name,               \
Lines 41-46 Link Here
41
    if (the##name->flag & APR_FILE_NOCLEANUP)                       \
47
    if (the##name->flag & APR_FILE_NOCLEANUP)                       \
42
        return APR_EINVAL;                                          \
48
        return APR_EINVAL;                                          \
43
    if (the##name->flag & APR_INHERIT) {                            \
49
    if (the##name->flag & APR_INHERIT) {                            \
50
        int flags = fcntl(the##name->name##des, F_GETFD);           \
51
        if (flags == -1)                                            \
52
            return errno;                                           \
53
        flags |= FD_CLOEXEC;                                        \
54
        if (fcntl(the##name->name##des, F_SETFD, flags) == -1)      \
55
            return errno;                                           \
44
        the##name->flag &= ~APR_INHERIT;                            \
56
        the##name->flag &= ~APR_INHERIT;                            \
45
        apr_pool_child_cleanup_set(the##name->pool,                 \
57
        apr_pool_child_cleanup_set(the##name->pool,                 \
46
                                   (void *)the##name,               \
58
                                   (void *)the##name,               \
(-)configure.in (+3 lines)
Lines 782-787 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
(-)poll/unix/epoll.c (-1 / +9 lines)
Lines 95-101 Link Here
95
    apr_status_t rv;
95
    apr_status_t rv;
96
    int fd;
96
    int fd;
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 errno;
105
        return errno;
Lines 338-345 Link Here
338
                                       apr_uint32_t flags)
342
                                       apr_uint32_t flags)
339
{
343
{
340
    int fd;
344
    int fd;
341
    
345
   
346
#ifdef HAVE_EPOLL_CREATE1
347
    fd = epoll_create1(EPOLL_CLOEXEC);
348
#else
342
    fd = epoll_create(size);
349
    fd = epoll_create(size);
350
#endif
343
    
351
    
344
    if (fd < 0) {
352
    if (fd < 0) {
345
        return apr_get_netos_error();
353
        return apr_get_netos_error();
(-)file_io/unix/open.c (+10 lines)
Lines 127-132 Link Here
127
        oflags |= O_BINARY;
127
        oflags |= O_BINARY;
128
    }
128
    }
129
#endif
129
#endif
130
#ifdef O_CLOEXEC
131
    if (!(flag & APR_FILE_NOCLEANUP))
132
	oflags |= O_CLOEXEC;
133
#endif
130
    
134
    
131
#if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
135
#if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
132
    oflags |= O_LARGEFILE;
136
    oflags |= O_LARGEFILE;
Lines 337-342 Link Here
337
        return APR_EINVAL;
341
        return APR_EINVAL;
338
    }
342
    }
339
    if (thefile->flags & APR_INHERIT) {
343
    if (thefile->flags & APR_INHERIT) {
344
        int flags = fcntl(thefile->filedes, F_GETFD);
345
        if (flags == -1)
346
             return errno;
347
        flags |= FD_CLOEXEC;
348
        if (fcntl(thefile->filedes, F_SETFD, flags) == -1)
349
             return errno;
340
        thefile->flags &= ~APR_INHERIT;
350
        thefile->flags &= ~APR_INHERIT;
341
        apr_pool_child_cleanup_set(thefile->pool,
351
        apr_pool_child_cleanup_set(thefile->pool,
342
                                   (void *)thefile,
352
                                   (void *)thefile,
(-)file_io/unix/filedup.c (-1 / +15 lines)
Lines 24-37 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
39
        if (!(old_file->flags & APR_INHERIT)) {
40
            flags = fcntl(old_file->filedes, F_GETFD);
41
            if (flags == -1)
42
                return errno;
43
            flags |= FD_CLOEXEC;
44
            if (fcntl(old_file->filedes, F_SETFD, flags) == -1)
45
                return errno;
46
        }
34
        rv = dup2(old_file->filedes, (*new_file)->filedes);
47
        rv = dup2(old_file->filedes, (*new_file)->filedes);
48
#endif
35
    } else {
49
    } else {
36
        rv = dup(old_file->filedes);
50
        rv = dup(old_file->filedes);
37
    }
51
    }

Return to bug 46425