]> granicus.if.org Git - python/commitdiff
Issue 14359: Only use O_CLOEXEC in _posixmodule.c if it is defined.
authorRoss Lagerwall <rosslagerwall@gmail.com>
Sun, 18 Mar 2012 13:55:10 +0000 (15:55 +0200)
committerRoss Lagerwall <rosslagerwall@gmail.com>
Sun, 18 Mar 2012 13:55:10 +0000 (15:55 +0200)
Based on patch from HervĂ© Coatanhay.

Modules/_posixsubprocess.c

index babf039611e04bcaa220be80d6b98207b378ab1b..8d3af6e877fbfd06244345a10eac01c63a5212e8 100644 (file)
@@ -204,7 +204,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);