apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruediger Pluem <rpl...@apache.org>
Subject Re: svn commit: r747990 - in /apr/apr/trunk: ./ file_io/netware/ file_io/unix/ include/arch/unix/ network_io/unix/ poll/unix/
Date Thu, 26 Feb 2009 13:58:44 GMT


On 02/26/2009 03:41 AM, bojan@apache.org wrote:
> Author: bojan
> Date: Thu Feb 26 02:41:21 2009
> New Revision: 747990
> 
> URL: http://svn.apache.org/viewvc?rev=747990&view=rev
> Log:
> 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.
> 
> Modified:
>     apr/apr/trunk/configure.in
>     apr/apr/trunk/file_io/netware/mktemp.c
>     apr/apr/trunk/file_io/unix/filedup.c
>     apr/apr/trunk/file_io/unix/mktemp.c
>     apr/apr/trunk/file_io/unix/open.c
>     apr/apr/trunk/include/arch/unix/apr_arch_inherit.h
>     apr/apr/trunk/network_io/unix/sockets.c
>     apr/apr/trunk/poll/unix/epoll.c
>     apr/apr/trunk/poll/unix/kqueue.c
>     apr/apr/trunk/poll/unix/pollset.c
>     apr/apr/trunk/poll/unix/port.c
> 

> Modified: apr/apr/trunk/include/arch/unix/apr_arch_inherit.h
> URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/arch/unix/apr_arch_inherit.h?rev=747990&r1=747989&r2=747990&view=diff
> ==============================================================================
> --- apr/apr/trunk/include/arch/unix/apr_arch_inherit.h (original)
> +++ apr/apr/trunk/include/arch/unix/apr_arch_inherit.h Thu Feb 26 02:41:21 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,               \
> @@ -35,12 +41,23 @@
>      return APR_SUCCESS;                                             \
>  }
>  
> +#define APR_SET_FD_CLOEXEC(fd)                                      \
> +do {                                                                \
> +    int flags;                                                      \
> +    if ((flags = fcntl(fd, F_GETFD)) == -1)                         \
> +        return errno;                                               \
> +    flags |= FD_CLOEXEC;                                            \
> +    if (fcntl(fd, F_SETFD, flags) == -1)                            \
> +        return errno;                                               \
> +} while (0)

IMHO doing a return in a macro that is just a block not a function
is bad. What if the return parameter of the function is not an int?
Furthermore it is a side effect that makes it hard to read the code.

> +
>  #define APR_IMPLEMENT_INHERIT_UNSET(name, flag, pool, cleanup)      \
>  apr_status_t apr_##name##_inherit_unset(apr_##name##_t *the##name)  \
>  {                                                                   \
>      if (the##name->flag & APR_FILE_NOCLEANUP)                       \
>          return APR_EINVAL;                                          \
>      if (the##name->flag & APR_INHERIT) {                            \
> +        APR_SET_FD_CLOEXEC(the##name->name##des);                   \
>          the##name->flag &= ~APR_INHERIT;                            \
>          apr_pool_child_cleanup_set(the##name->pool,                 \
>                                     (void *)the##name,               \
> 

Regards

RĂ¼diger

Mime
View raw message