diff options
author | Steve Dower <steve.dower@python.org> | 2020-10-19 15:50:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-19 15:50:36 +0100 |
commit | c82f10450c547eb94a04ee17b7c816ff31948297 (patch) | |
tree | ad305c05c5745e1a5e7c136545bec7eefa741e32 /Modules/_posixsubprocess.c | |
parent | eee6bb50c69d94280f43b47390ea9d1b5f42930c (diff) | |
parent | b580ed1d9d55461d8dde027411b90be26cae131e (diff) | |
download | cpython-git-bpo-39107.tar.gz |
Merge branch 'master' into bpo-39107bpo-39107
Diffstat (limited to 'Modules/_posixsubprocess.c')
-rw-r--r-- | Modules/_posixsubprocess.c | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index 5d1691ace4..d08c47980e 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -1,5 +1,6 @@ /* Authors: Gregory P. Smith & Jeffrey Yasskin */ #include "Python.h" +#include "pycore_fileutils.h" #if defined(HAVE_PIPE2) && !defined(_GNU_SOURCE) # define _GNU_SOURCE #endif @@ -250,7 +251,6 @@ _close_fds_by_brute_force(long start_fd, PyObject *py_fds_to_keep) long end_fd = safe_get_max_fd(); Py_ssize_t num_fds_to_keep = PyTuple_GET_SIZE(py_fds_to_keep); Py_ssize_t keep_seq_idx; - int fd_num; /* As py_fds_to_keep is sorted we can loop through the list closing * fds in between any in the keep list falling within our range. */ for (keep_seq_idx = 0; keep_seq_idx < num_fds_to_keep; ++keep_seq_idx) { @@ -258,21 +258,11 @@ _close_fds_by_brute_force(long start_fd, PyObject *py_fds_to_keep) int keep_fd = PyLong_AsLong(py_keep_fd); if (keep_fd < start_fd) continue; - for (fd_num = start_fd; fd_num < keep_fd; ++fd_num) { - close(fd_num); - } + _Py_closerange(start_fd, keep_fd - 1); start_fd = keep_fd + 1; } if (start_fd <= end_fd) { -#if defined(__FreeBSD__) - /* Any errors encountered while closing file descriptors are ignored */ - closefrom(start_fd); -#else - for (fd_num = start_fd; fd_num < end_fd; ++fd_num) { - /* Ignore errors */ - (void)close(fd_num); - } -#endif + _Py_closerange(start_fd, end_fd); } } |