diff options
author | Ross Lagerwall <rosslagerwall@gmail.com> | 2012-03-18 13:55:10 (GMT) |
---|---|---|
committer | Ross Lagerwall <rosslagerwall@gmail.com> | 2012-03-18 13:55:10 (GMT) |
commit | 5802fdf31f80c5ba5f6eec149b418cf83e9c5f33 (patch) | |
tree | 3ec9f6f902e049e900987765afb177c8aeb1fba7 /Modules/_posixsubprocess.c | |
parent | 7dabfede34bcef7a5d547adf2aabd02b9079d6c5 (diff) | |
download | cpython-5802fdf31f80c5ba5f6eec149b418cf83e9c5f33.zip cpython-5802fdf31f80c5ba5f6eec149b418cf83e9c5f33.tar.gz cpython-5802fdf31f80c5ba5f6eec149b418cf83e9c5f33.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.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index babf039..8d3af6e 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -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); |