diff options
author | Stefan Fritsch <sf@apache.org> | 2011-10-15 20:54:07 +0000 |
---|---|---|
committer | Stefan Fritsch <sf@apache.org> | 2011-10-15 20:54:07 +0000 |
commit | 5265fe9c3b7a8df613740cc4965b3f0103744f28 (patch) | |
tree | 59692e02b573455e75bdd63ebbbd50d9395ff6dd /file_io/unix | |
parent | 3430659362e36a2386f2f1cd4ddee0d8b76016de (diff) | |
download | apr-5265fe9c3b7a8df613740cc4965b3f0103744f28.tar.gz |
Avoid fcntl() calls if support for O_CLOEXEC works.
PR: 48557
Submitted by: Mike Frysinger <vapier gentoo org>
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1183698 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/unix')
-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 ea085f756..36be4a706 100644 --- a/file_io/unix/open.c +++ b/file_io/unix/open.c @@ -178,19 +178,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 } } |