summaryrefslogtreecommitdiffstats
path: root/Modules/_posixsubprocess.c
diff options
context:
space:
mode:
authorRoss Lagerwall <rosslagerwall@gmail.com>2012-03-19 04:08:43 (GMT)
committerRoss Lagerwall <rosslagerwall@gmail.com>2012-03-19 04:08:43 (GMT)
commit71faefc37e4a74d72e9a56243a085bfddd9209e0 (patch)
treee01a21553e4d22bc2378f4da1d8ca1e7ed9836bf /Modules/_posixsubprocess.c
parent1623afff679e222bff8f2a4910d9eb9019c8db2b (diff)
downloadcpython-71faefc37e4a74d72e9a56243a085bfddd9209e0.zip
cpython-71faefc37e4a74d72e9a56243a085bfddd9209e0.tar.gz
cpython-71faefc37e4a74d72e9a56243a085bfddd9209e0.tar.bz2
Issue #14359: Only use O_CLOEXEC in _posixmodule.c if it is defined.
Based on patch from Hervé Coatanhay.
Diffstat (limited to 'Modules/_posixsubprocess.c')
-rw-r--r--Modules/_posixsubprocess.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
index d520c8c..81274e1 100644
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -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);