You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bo...@apache.org on 2009/06/23 01:54:28 UTC
svn commit: r787448 - in /apr/apr/branches/1.3.x: ./ file_io/netware/
file_io/unix/ include/arch/unix/ network_io/unix/ poll/unix/
Author: bojan
Date: Mon Jun 22 23:54:28 2009
New Revision: 787448
URL: http://svn.apache.org/viewvc?rev=787448&view=rev
Log:
Backport r747990, r748361, r748371, r748565, r748988, r749810, r783958
from the trunk.
Set CLOEXEC flags where appropriate. Either use new O_CLOEXEC flag and
associated functions, such as dup3(), accept4(), epoll_create1() etc., or
simply set CLOEXEC flag using fcntl().
Patch by Stefan Fritsch <sf sfritsch.de> and
Arkadiusz Miskiewicz <arekm pld-linux.org>.
PR 46425.
fix unused variable warning for builds without HAVE_DUP3
Unroll APR_SET_FD_CLOEXEC macro.
* One missing unroll of APR_SET_FD_CLOEXEC.
Document CLOEXEC patch.
Only set CLOEXEC on dup() if both NOCLEANUP and INHERIT flags are clear.
Retain the INHERIT/NOCLEANUP flags of new_file in apr_file_dup2().
Patch by Stefan Fritsch <sf sfritsch.de>.
Modified:
apr/apr/branches/1.3.x/ (props changed)
apr/apr/branches/1.3.x/CHANGES
apr/apr/branches/1.3.x/configure.in
apr/apr/branches/1.3.x/file_io/netware/mktemp.c
apr/apr/branches/1.3.x/file_io/unix/filedup.c
apr/apr/branches/1.3.x/file_io/unix/mktemp.c
apr/apr/branches/1.3.x/file_io/unix/open.c
apr/apr/branches/1.3.x/include/arch/unix/apr_arch_inherit.h
apr/apr/branches/1.3.x/network_io/unix/sockets.c
apr/apr/branches/1.3.x/poll/unix/epoll.c
apr/apr/branches/1.3.x/poll/unix/kqueue.c
apr/apr/branches/1.3.x/poll/unix/port.c
Propchange: apr/apr/branches/1.3.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jun 22 23:54:28 2009
@@ -1 +1,2 @@
-/apr/apr/trunk:712674,733052,742752,782838,783398
+/apr/apr/branches/1.4.x:783970
+/apr/apr/trunk:712674,733052,742752,747990,748361,748371,748565,748988,749810,782838,783398,783958
Modified: apr/apr/branches/1.3.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/CHANGES?rev=787448&r1=787447&r2=787448&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.3.x/CHANGES [utf-8] Mon Jun 22 23:54:28 2009
@@ -1,7 +1,10 @@
-*- coding: utf-8 -*-
Changes for APR 1.3.6
-
+ *) Set CLOEXEC flags where appropriate. Either use new O_CLOEXEC flag and
+ associated functions, such as dup3(), accept4(), epoll_create1() etc.,
+ or simply set CLOEXEC flag using fcntl(). PR 46425. [Stefan Fritsch
+ <sf sfritsch.de>, Arkadiusz Miskiewicz <arekm pld-linux.org>]
Changes for APR 1.3.5
Modified: apr/apr/branches/1.3.x/configure.in
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/configure.in?rev=787448&r1=787447&r2=787448&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/configure.in (original)
+++ apr/apr/branches/1.3.x/configure.in Mon Jun 22 23:54:28 2009
@@ -775,6 +775,23 @@
AC_DEFINE([HAVE_EPOLL], 1, [Define if the epoll interface is supported])
fi
+dnl ----------------------------- Checking for extended file descriptor handling
+AC_CHECK_FUNCS(dup3 accept4 epoll_create1)
+
+AC_CACHE_CHECK([for SOCK_CLOEXEC support], [apr_cv_sock_cloexec],
+[AC_TRY_RUN([
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int main()
+{
+ return socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, 0) == -1;
+}], [apr_cv_sock_cloexec=yes], [apr_cv_sock_cloexec=no], [apr_cv_sock_cloexec=no])])
+
+if test "$apr_cv_sock_cloexec" = "yes"; then
+ AC_DEFINE([HAVE_SOCK_CLOEXEC], 1, [Define if the SOCK_CLOEXEC flag is supported])
+fi
+
dnl ----------------------------- Checking for missing POSIX thread functions
AC_CHECK_FUNCS([getpwnam_r getpwuid_r getgrnam_r getgrgid_r])
Modified: apr/apr/branches/1.3.x/file_io/netware/mktemp.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/file_io/netware/mktemp.c?rev=787448&r1=787447&r2=787448&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/file_io/netware/mktemp.c (original)
+++ apr/apr/branches/1.3.x/file_io/netware/mktemp.c Mon Jun 22 23:54:28 2009
@@ -19,6 +19,7 @@
#include "apr_strings.h" /* prototype of apr_mkstemp() */
#include "apr_arch_file_io.h" /* prototype of apr_mkstemp() */
#include "apr_portable.h" /* for apr_os_file_put() */
+#include "apr_arch_inherit.h"
#include <stdlib.h> /* for mkstemp() - Single Unix */
@@ -43,6 +44,15 @@
if (!(flags & APR_FILE_NOCLEANUP)) {
+ int flags;
+
+ if ((flags = fcntl((*fp)->filedes, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl((*fp)->filedes, F_SETFD, flags) == -1)
+ return errno;
+
apr_pool_cleanup_register((*fp)->pool, (void *)(*fp),
apr_unix_file_cleanup,
apr_unix_child_file_cleanup);
Modified: apr/apr/branches/1.3.x/file_io/unix/filedup.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/file_io/unix/filedup.c?rev=787448&r1=787447&r2=787448&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/file_io/unix/filedup.c (original)
+++ apr/apr/branches/1.3.x/file_io/unix/filedup.c Mon Jun 22 23:54:28 2009
@@ -25,13 +25,36 @@
int which_dup)
{
int rv;
-
+#ifdef HAVE_DUP3
+ int flags = 0;
+#endif
+
if (which_dup == 2) {
if ((*new_file) == NULL) {
/* We can't dup2 unless we have a valid new_file */
return APR_EINVAL;
}
+#ifdef HAVE_DUP3
+ if (!((*new_file)->flags & (APR_FILE_NOCLEANUP|APR_INHERIT)))
+ flags |= O_CLOEXEC;
+ rv = dup3(old_file->filedes, (*new_file)->filedes, flags);
+#else
rv = dup2(old_file->filedes, (*new_file)->filedes);
+ if (!((*new_file)->flags & (APR_FILE_NOCLEANUP|APR_INHERIT))) {
+ int flags;
+
+ if (rv == -1)
+ return errno;
+
+ if ((flags = fcntl((*new_file)->filedes, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl((*new_file)->filedes, F_SETFD, flags) == -1)
+ return errno;
+
+ }
+#endif
} else {
rv = dup(old_file->filedes);
}
Modified: apr/apr/branches/1.3.x/file_io/unix/mktemp.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/file_io/unix/mktemp.c?rev=787448&r1=787447&r2=787448&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/file_io/unix/mktemp.c (original)
+++ apr/apr/branches/1.3.x/file_io/unix/mktemp.c Mon Jun 22 23:54:28 2009
@@ -51,6 +51,7 @@
#include "apr_strings.h" /* prototype of apr_mkstemp() */
#include "apr_arch_file_io.h" /* prototype of apr_mkstemp() */
#include "apr_portable.h" /* for apr_os_file_put() */
+#include "apr_arch_inherit.h"
#ifndef HAVE_MKSTEMP
@@ -203,6 +204,15 @@
(*fp)->fname = apr_pstrdup(p, template);
if (!(flags & APR_FILE_NOCLEANUP)) {
+ int flags;
+
+ if ((flags = fcntl(fd, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl(fd, F_SETFD, flags) == -1)
+ return errno;
+
apr_pool_cleanup_register((*fp)->pool, (void *)(*fp),
apr_unix_file_cleanup,
apr_unix_child_file_cleanup);
Modified: apr/apr/branches/1.3.x/file_io/unix/open.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/file_io/unix/open.c?rev=787448&r1=787447&r2=787448&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/file_io/unix/open.c (original)
+++ apr/apr/branches/1.3.x/file_io/unix/open.c Mon Jun 22 23:54:28 2009
@@ -127,7 +127,15 @@
oflags |= O_BINARY;
}
#endif
-
+
+#ifdef O_CLOEXEC
+ /* Introduced in Linux 2.6.23. Silently ignored on earlier Linux kernels.
+ */
+ if (!(flag & APR_FILE_NOCLEANUP)) {
+ oflags |= O_CLOEXEC;
+}
+#endif
+
#if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
oflags |= O_LARGEFILE;
#elif defined(O_LARGEFILE)
@@ -155,6 +163,16 @@
if (fd < 0) {
return errno;
}
+ if (!(flag & APR_FILE_NOCLEANUP)) {
+ int flags;
+
+ if ((flags = fcntl(fd, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl(fd, F_SETFD, flags) == -1)
+ return errno;
+ }
(*new) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
(*new)->pool = pool;
@@ -337,6 +355,15 @@
return APR_EINVAL;
}
if (thefile->flags & APR_INHERIT) {
+ int flags;
+
+ if ((flags = fcntl(thefile->filedes, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl(thefile->filedes, F_SETFD, flags) == -1)
+ return errno;
+
thefile->flags &= ~APR_INHERIT;
apr_pool_child_cleanup_set(thefile->pool,
(void *)thefile,
Modified: apr/apr/branches/1.3.x/include/arch/unix/apr_arch_inherit.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/include/arch/unix/apr_arch_inherit.h?rev=787448&r1=787447&r2=787448&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/include/arch/unix/apr_arch_inherit.h (original)
+++ apr/apr/branches/1.3.x/include/arch/unix/apr_arch_inherit.h Mon Jun 22 23:54:28 2009
@@ -27,6 +27,12 @@
if (the##name->flag & APR_FILE_NOCLEANUP) \
return APR_EINVAL; \
if (!(the##name->flag & APR_INHERIT)) { \
+ int flags = fcntl(the##name->name##des, F_GETFD); \
+ if (flags == -1) \
+ return errno; \
+ flags &= ~(FD_CLOEXEC); \
+ if (fcntl(the##name->name##des, F_SETFD, flags) == -1) \
+ return errno; \
the##name->flag |= APR_INHERIT; \
apr_pool_child_cleanup_set(the##name->pool, \
(void *)the##name, \
@@ -41,6 +47,12 @@
if (the##name->flag & APR_FILE_NOCLEANUP) \
return APR_EINVAL; \
if (the##name->flag & APR_INHERIT) { \
+ int flags; \
+ if ((flags = fcntl(the##name->name##des, F_GETFD)) == -1) \
+ return errno; \
+ flags |= FD_CLOEXEC; \
+ if (fcntl(the##name->name##des, F_SETFD, flags) == -1) \
+ return errno; \
the##name->flag &= ~APR_INHERIT; \
apr_pool_child_cleanup_set(the##name->pool, \
(void *)the##name, \
Modified: apr/apr/branches/1.3.x/network_io/unix/sockets.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/network_io/unix/sockets.c?rev=787448&r1=787447&r2=787448&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/network_io/unix/sockets.c (original)
+++ apr/apr/branches/1.3.x/network_io/unix/sockets.c Mon Jun 22 23:54:28 2009
@@ -83,7 +83,11 @@
apr_status_t apr_socket_create(apr_socket_t **new, int ofamily, int type,
int protocol, apr_pool_t *cont)
{
- int family = ofamily;
+ int family = ofamily, flags = 0;
+
+#ifdef HAVE_SOCK_CLOEXEC
+ flags |= SOCK_CLOEXEC;
+#endif
if (family == APR_UNSPEC) {
#if APR_HAVE_IPV6
@@ -96,19 +100,19 @@
alloc_socket(new, cont);
#ifndef BEOS_R5
- (*new)->socketdes = socket(family, type, protocol);
+ (*new)->socketdes = socket(family, type|flags, protocol);
#else
/* For some reason BeOS R5 has an unconventional protocol numbering,
* so we need to translate here. */
switch (protocol) {
case 0:
- (*new)->socketdes = socket(family, type, 0);
+ (*new)->socketdes = socket(family, type|flags, 0);
break;
case APR_PROTO_TCP:
- (*new)->socketdes = socket(family, type, IPPROTO_TCP);
+ (*new)->socketdes = socket(family, type|flags, IPPROTO_TCP);
break;
case APR_PROTO_UDP:
- (*new)->socketdes = socket(family, type, IPPROTO_UDP);
+ (*new)->socketdes = socket(family, type|flags, IPPROTO_UDP);
break;
case APR_PROTO_SCTP:
default:
@@ -121,7 +125,7 @@
#if APR_HAVE_IPV6
if ((*new)->socketdes < 0 && ofamily == APR_UNSPEC) {
family = APR_INET;
- (*new)->socketdes = socket(family, type, protocol);
+ (*new)->socketdes = socket(family, type|flags, protocol);
}
#endif
@@ -130,6 +134,19 @@
}
set_socket_vars(*new, family, type, protocol);
+#ifndef HAVE_SOCK_CLOEXEC
+ {
+ int flags;
+
+ if ((flags = fcntl((*new)->socketdes, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
+ return errno;
+ }
+#endif
+
(*new)->timeout = -1;
(*new)->inherit = 0;
apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
@@ -181,7 +198,11 @@
sa.salen = sizeof(sa.sa);
+#ifdef HAVE_ACCEPT4
+ s = accept4(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen, SOCK_CLOEXEC);
+#else
s = accept(sock->socketdes, (struct sockaddr *)&sa.sa, &sa.salen);
+#endif
if (s < 0) {
return errno;
@@ -255,6 +276,19 @@
(*new)->local_interface_unknown = 1;
}
+#ifndef HAVE_ACCEPT4
+ {
+ int flags;
+
+ if ((flags = fcntl((*new)->socketdes, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl((*new)->socketdes, F_SETFD, flags) == -1)
+ return errno;
+ }
+#endif
+
(*new)->inherit = 0;
apr_pool_cleanup_register((*new)->pool, (void *)(*new), socket_cleanup,
socket_cleanup);
Modified: apr/apr/branches/1.3.x/poll/unix/epoll.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/poll/unix/epoll.c?rev=787448&r1=787447&r2=787448&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/poll/unix/epoll.c (original)
+++ apr/apr/branches/1.3.x/poll/unix/epoll.c Mon Jun 22 23:54:28 2009
@@ -15,6 +15,7 @@
*/
#include "apr_arch_poll_private.h"
+#include "apr_arch_inherit.h"
#ifdef POLLSET_USES_EPOLL
@@ -95,12 +96,29 @@
#endif
int fd;
+#ifdef HAVE_EPOLL_CREATE1
+ fd = epoll_create1(EPOLL_CLOEXEC);
+#else
fd = epoll_create(size);
+#endif
if (fd < 0) {
*pollset = NULL;
return errno;
}
+#ifndef HAVE_EPOLL_CREATE1
+ {
+ int flags;
+
+ if ((flags = fcntl(fd, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl(fd, F_SETFD, flags) == -1)
+ return errno;
+ }
+#endif
+
*pollset = apr_palloc(p, sizeof(**pollset));
#if APR_HAS_THREADS
if ((flags & APR_POLLSET_THREADSAFE) &&
@@ -319,12 +337,29 @@
{
int fd;
+#ifdef HAVE_EPOLL_CREATE1
+ fd = epoll_create1(EPOLL_CLOEXEC);
+#else
fd = epoll_create(size);
+#endif
if (fd < 0) {
*pollcb = NULL;
return apr_get_netos_error();
}
+
+#ifndef HAVE_EPOLL_CREATE1
+ {
+ int flags;
+
+ if ((flags = fcntl(fd, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl(fd, F_SETFD, flags) == -1)
+ return errno;
+ }
+#endif
*pollcb = apr_palloc(p, sizeof(**pollcb));
(*pollcb)->nalloc = size;
Modified: apr/apr/branches/1.3.x/poll/unix/kqueue.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/poll/unix/kqueue.c?rev=787448&r1=787447&r2=787448&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/poll/unix/kqueue.c (original)
+++ apr/apr/branches/1.3.x/poll/unix/kqueue.c Mon Jun 22 23:54:28 2009
@@ -15,6 +15,7 @@
*/
#include "apr_arch_poll_private.h"
+#include "apr_arch_inherit.h"
#ifdef POLLSET_USES_KQUEUE
@@ -101,6 +102,17 @@
return apr_get_netos_error();
}
+ {
+ int flags;
+
+ if ((flags = fcntl((*pollset)->kqueue_fd, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl((*pollset)->kqueue_fd, F_SETFD, flags) == -1)
+ return errno;
+ }
+
apr_pool_cleanup_register(p, (void *) (*pollset), backend_cleanup,
apr_pool_cleanup_null);
@@ -309,7 +321,18 @@
*pollcb = NULL;
return apr_get_netos_error();
}
-
+
+ {
+ int flags;
+
+ if ((flags = fcntl(fd, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl(fd, F_SETFD, flags) == -1)
+ return errno;
+ }
+
*pollcb = apr_palloc(p, sizeof(**pollcb));
(*pollcb)->nalloc = size;
(*pollcb)->pool = p;
Modified: apr/apr/branches/1.3.x/poll/unix/port.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/poll/unix/port.c?rev=787448&r1=787447&r2=787448&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/poll/unix/port.c (original)
+++ apr/apr/branches/1.3.x/poll/unix/port.c Mon Jun 22 23:54:28 2009
@@ -16,6 +16,7 @@
#include "apr_arch_poll_private.h"
#include "apr_atomic.h"
+#include "apr_arch_inherit.h"
#ifdef POLLSET_USES_PORT
@@ -127,6 +128,17 @@
return APR_ENOMEM;
}
+ {
+ int flags;
+
+ if ((flags = fcntl((*pollset)->port_fd, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl((*pollset)->port_fd, F_SETFD, flags) == -1)
+ return errno;
+ }
+
apr_pool_cleanup_register(p, (void *) (*pollset), backend_cleanup,
apr_pool_cleanup_null);
@@ -391,6 +403,17 @@
return apr_get_netos_error();
}
+ {
+ int flags;
+
+ if ((flags = fcntl(fd, F_GETFD)) == -1)
+ return errno;
+
+ flags |= FD_CLOEXEC;
+ if (fcntl(fd, F_SETFD, flags) == -1)
+ return errno;
+ }
+
*pollcb = apr_palloc(p, sizeof(**pollcb));
(*pollcb)->nalloc = size;
(*pollcb)->pool = p;
Re: svn commit: r787448 - in /apr/apr/branches/1.3.x: ./
file_io/netware/ file_io/unix/ include/arch/unix/ network_io/unix/ poll/unix/
Posted by Felipe Cerqueira skylazart <sk...@gmail.com>.
On Mon, Jun 22, 2009 at 8:58 PM, Bojan Smojver <bo...@rexursive.com> wrote:
> On Mon, 2009-06-22 at 23:54 +0000, bojan@apache.org wrote:
> > Backport r747990, r748361, r748371, r748565, r748988, r749810, r783958
> > from the trunk.
> >
> > Set CLOEXEC flags where appropriate.
>
> Given there were no -1 voices to my e-mail, here is another chance to do
> the same through CTR. Have at it folks and let me know if we should
> revert this.
Hi Bojan,
I dont think there is someone re-using a descriptor inside a new process
after a execv(). It doenst make sense for me. So, I think the patch wont
cause any problem to anybody.
Just my 2 cents
>
>
> --
> Bojan
>
>
--
Felipe Cerqueira / skylazart
skylazart [at] gmail.com
Re: svn commit: r787448 - in /apr/apr/branches/1.3.x: ./
file_io/netware/ file_io/unix/ include/arch/unix/ network_io/unix/
poll/unix/
Posted by Bojan Smojver <bo...@rexursive.com>.
On Mon, 2009-06-22 at 23:54 +0000, bojan@apache.org wrote:
> Backport r747990, r748361, r748371, r748565, r748988, r749810, r783958
> from the trunk.
>
> Set CLOEXEC flags where appropriate.
Given there were no -1 voices to my e-mail, here is another chance to do
the same through CTR. Have at it folks and let me know if we should
revert this.
--
Bojan