]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #14359: Only use O_CLOEXEC in _posixmodule.c if it is defined.
authorRoss Lagerwall <rosslagerwall@gmail.com>
Mon, 19 Mar 2012 04:08:43 +0000 (06:08 +0200)
committerRoss Lagerwall <rosslagerwall@gmail.com>
Mon, 19 Mar 2012 04:08:43 +0000 (06:08 +0200)
Based on patch from Hervé Coatanhay.

Misc/ACKS
Misc/NEWS
Modules/_posixsubprocess.c

index 2b3dad5424fc4acfff9e69d14de885f9091c6bcc..77cec5c645eba9511d575360ad93139a07982a8a 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -173,6 +173,7 @@ Mike Clarkson
 Andrew Clegg
 Brad Clements
 Steve Clift
+Hervé Coatanhay
 Nick Coghlan
 Josh Cogliati
 Dave Cole
index b1a60d37d2eae329d0d5f66efd974353baae579a..40b17fc87f6bd457ee6661e31161a81b4e21e525 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -78,6 +78,12 @@ Extension Modules
 - Issue #14212: The re module didn't retain a reference to buffers it was
   scanning, resulting in segfaults.
 
+Build
+-----
+
+- Issue #14359: Only use O_CLOEXEC in _posixmodule.c if it is defined.
+  Based on patch from Hervé Coatanhay.
+
 
 What's New in Python 3.2.3 release candidate 2?
 ===============================================
index d520c8c7692efc007b80da3f102e774b32f79e68..81274e12c8bacaf01e0f5595d60bb2f85558baad 100644 (file)
@@ -202,7 +202,18 @@ _close_open_fd_range_safe(int start_fd, int end_fd, PyObject* py_fds_to_keep)
     int fd_dir_fd;
     if (start_fd >= end_fd)
         return;
-        fd_dir_fd = open(FD_DIR, O_RDONLY | O_CLOEXEC, 0);
+#ifdef O_CLOEXEC
+    fd_dir_fd = open(FD_DIR, O_RDONLY | O_CLOEXEC, 0);
+#else
+    fd_dir_fd = open(FD_DIR, O_RDONLY, 0);
+#ifdef FD_CLOEXEC
+    {
+        int old = fcntl(fd_dir_fd, F_GETFD);
+        if (old != -1)
+            fcntl(fd_dir_fd, F_SETFD, old | FD_CLOEXEC);
+    }
+#endif
+#endif
     if (fd_dir_fd == -1) {
         /* No way to get a list of open fds. */
         _close_fds_by_brute_force(start_fd, end_fd, py_fds_to_keep);