summaryrefslogtreecommitdiff
path: root/Modules/_posixsubprocess.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_posixsubprocess.c')
-rw-r--r--Modules/_posixsubprocess.c16
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);
}
}