summaryrefslogtreecommitdiff
path: root/lang/python35/files/patch-Modules___posixsubprocess.c
blob: 54e31f476b3b578db10b9e22e7bc0a147ed3cbe1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Add closefrom(2) support
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=242274
# https://bugs.python.org/issue38061
# TODO: Upstream

--- Modules/_posixsubprocess.c.orig	2019-11-01 23:02:34 UTC
+++ Modules/_posixsubprocess.c
@@ -233,8 +233,15 @@ _close_fds_by_brute_force(long start_fd, PyObject *py_
         start_fd = keep_fd + 1;
     }
     if (start_fd <= end_fd) {
-        for (fd_num = start_fd; fd_num < end_fd; ++fd_num) {
-            close(fd_num);
+#ifdef __FreeBSD__
+        if (end_fd >= sysconf(_SC_OPEN_MAX)) {
+            closefrom(start_fd);
+        } else
+#endif
+        {
+            for (fd_num = start_fd; fd_num < end_fd; ++fd_num) {
+                close(fd_num);
+            }
         }
     }
 }