diff options
Diffstat (limited to 'file_io/unix/open.c')
-rw-r--r-- | file_io/unix/open.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/file_io/unix/open.c b/file_io/unix/open.c index 3b7dc27c2..ea17f79d8 100644 --- a/file_io/unix/open.c +++ b/file_io/unix/open.c @@ -177,19 +177,29 @@ APR_DECLARE(apr_status_t) apr_file_open(apr_file_t **new, return errno; } if (!(flag & APR_FOPEN_NOCLEANUP)) { - int flags; - - if ((flags = fcntl(fd, F_GETFD)) == -1) { - close(fd); - return errno; - } +#ifdef O_CLOEXEC + static int has_o_cloexec = 0; + if (!has_o_cloexec) +#endif + { + int flags; - if ((flags & FD_CLOEXEC) == 0) { - flags |= FD_CLOEXEC; - if (fcntl(fd, F_SETFD, flags) == -1) { + if ((flags = fcntl(fd, F_GETFD)) == -1) { close(fd); return errno; } + if ((flags & FD_CLOEXEC) == 0) { + flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, flags) == -1) { + close(fd); + return errno; + } + } +#ifdef O_CLOEXEC + else { + has_o_cloexec = 1; + } +#endif } } |