GME  13
apr_arch_inherit.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef INHERIT_H
00018 #define INHERIT_H
00019 
00020 #include "apr_inherit.h"
00021 
00022 #define APR_INHERIT (1 << 24)    /* Must not conflict with other bits */
00023 
00024 #define APR_IMPLEMENT_INHERIT_SET(name, flag, pool, cleanup)        \
00025 apr_status_t apr_##name##_inherit_set(apr_##name##_t *the##name)    \
00026 {                                                                   \
00027     if (the##name->flag & APR_FOPEN_NOCLEANUP)                      \
00028         return APR_EINVAL;                                          \
00029     if (!(the##name->flag & APR_INHERIT)) {                         \
00030         int flags = fcntl(the##name->name##des, F_GETFD);           \
00031         if (flags == -1)                                            \
00032             return errno;                                           \
00033         flags &= ~(FD_CLOEXEC);                                     \
00034         if (fcntl(the##name->name##des, F_SETFD, flags) == -1)      \
00035             return errno;                                           \
00036         the##name->flag |= APR_INHERIT;                             \
00037         apr_pool_child_cleanup_set(the##name->pool,                 \
00038                                    (void *)the##name,               \
00039                                    cleanup, apr_pool_cleanup_null); \
00040     }                                                               \
00041     return APR_SUCCESS;                                             \
00042 }
00043 
00044 #define APR_IMPLEMENT_INHERIT_UNSET(name, flag, pool, cleanup)      \
00045 apr_status_t apr_##name##_inherit_unset(apr_##name##_t *the##name)  \
00046 {                                                                   \
00047     if (the##name->flag & APR_FOPEN_NOCLEANUP)                      \
00048         return APR_EINVAL;                                          \
00049     if (the##name->flag & APR_INHERIT) {                            \
00050         int flags;                                                  \
00051         if ((flags = fcntl(the##name->name##des, F_GETFD)) == -1)   \
00052             return errno;                                           \
00053         flags |= FD_CLOEXEC;                                        \
00054         if (fcntl(the##name->name##des, F_SETFD, flags) == -1)      \
00055             return errno;                                           \
00056         the##name->flag &= ~APR_INHERIT;                            \
00057         apr_pool_child_cleanup_set(the##name->pool,                 \
00058                                    (void *)the##name,               \
00059                                    cleanup, cleanup);               \
00060     }                                                               \
00061     return APR_SUCCESS;                                             \
00062 }
00063 
00064 #endif  /* ! INHERIT_H */