apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1183698 - in /apr/apr/trunk: CHANGES file_io/unix/open.c
Date Sat, 15 Oct 2011 20:54:07 GMT
Author: sf
Date: Sat Oct 15 20:54:07 2011
New Revision: 1183698

URL: http://svn.apache.org/viewvc?rev=1183698&view=rev
Log:
Avoid fcntl() calls if support for O_CLOEXEC works.
PR: 48557
Submitted by: Mike Frysinger <vapier gentoo org>

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/file_io/unix/open.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1183698&r1=1183697&r2=1183698&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Sat Oct 15 20:54:07 2011
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) apr_file_open: Avoid fcntl() calls if support for O_CLOEXEC works.
+     PR 48557. [Mike Frysinger <vapier gentoo org>]
+
   *) apr_socket_opt_set: Add support for APR_SO_BROADCAST. PR 46389.
      [Armin Müller <mueller itestra com>]
 

Modified: apr/apr/trunk/file_io/unix/open.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/unix/open.c?rev=1183698&r1=1183697&r2=1183698&view=diff
==============================================================================
--- apr/apr/trunk/file_io/unix/open.c (original)
+++ apr/apr/trunk/file_io/unix/open.c Sat Oct 15 20:54:07 2011
@@ -178,19 +178,29 @@ APR_DECLARE(apr_status_t) apr_file_open(
        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
         }
     }
 



Mime
View raw message