summaryrefslogtreecommitdiff
path: root/file_io/unix
diff options
context:
space:
mode:
authorsf <sf@13f79535-47bb-0310-9956-ffa450edef68>2011-10-15 21:34:24 +0000
committersf <sf@13f79535-47bb-0310-9956-ffa450edef68>2011-10-15 21:34:24 +0000
commitbd45e6c930998e2b2443041ae9ed8ba28b6f5d29 (patch)
tree13e06692c6b578a2fecef4910cba51bb2fef7e4d /file_io/unix
parent76d46e9b89f79d1600c660c4008ceb2a2a60aac5 (diff)
downloadlibapr-bd45e6c930998e2b2443041ae9ed8ba28b6f5d29.tar.gz
Backport r1183698:
Avoid fcntl() calls if support for O_CLOEXEC works. PR: 48557 Submitted by: Mike Frysinger <vapier gentoo org> git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/1.4.x@1183732 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/unix')
-rw-r--r--file_io/unix/open.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/file_io/unix/open.c b/file_io/unix/open.c
index 0d37d0fb4..6373ee5ba 100644
--- a/file_io/unix/open.c
+++ b/file_io/unix/open.c
@@ -171,19 +171,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
}
}