summaryrefslogtreecommitdiffstats
path: root/Modules/_posixsubprocess.c
diff options
context:
space:
mode:
authorCharles-François Natali <cf.natali@gmail.com>2013-08-25 16:28:44 (GMT)
committerCharles-François Natali <cf.natali@gmail.com>2013-08-25 16:28:44 (GMT)
commita439b32cf02a78ca326d131897c3e5b1883210f2 (patch)
tree733ee396bac4e2299ae23a13c5e1dee98deef9ed /Modules/_posixsubprocess.c
parent58b3ebfab92d4241e65fbb0f34c84746fcbe347b (diff)
parentc20a7b977e919f1c261e955d3013ffae9ed0702f (diff)
downloadcpython-a439b32cf02a78ca326d131897c3e5b1883210f2.zip
cpython-a439b32cf02a78ca326d131897c3e5b1883210f2.tar.gz
cpython-a439b32cf02a78ca326d131897c3e5b1883210f2.tar.bz2
Merge.
Diffstat (limited to 'Modules/_posixsubprocess.c')
-rw-r--r--Modules/_posixsubprocess.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c
index c4a6b7b..8d70107 100644
--- a/Modules/_posixsubprocess.c
+++ b/Modules/_posixsubprocess.c
@@ -412,17 +412,6 @@ child_exec(char *const exec_array[],
POSIX_CALL(close(errwrite));
}
- if (close_fds) {
- int local_max_fd = max_fd;
-#if defined(__NetBSD__)
- local_max_fd = fcntl(0, F_MAXFD);
- if (local_max_fd < 0)
- local_max_fd = max_fd;
-#endif
- /* TODO HP-UX could use pstat_getproc() if anyone cares about it. */
- _close_open_fd_range(3, local_max_fd, py_fds_to_keep);
- }
-
if (cwd)
POSIX_CALL(chdir(cwd));
@@ -451,6 +440,18 @@ child_exec(char *const exec_array[],
/* Py_DECREF(result); - We're about to exec so why bother? */
}
+ /* close FDs after executing preexec_fn, which might open FDs */
+ if (close_fds) {
+ int local_max_fd = max_fd;
+#if defined(__NetBSD__)
+ local_max_fd = fcntl(0, F_MAXFD);
+ if (local_max_fd < 0)
+ local_max_fd = max_fd;
+#endif
+ /* TODO HP-UX could use pstat_getproc() if anyone cares about it. */
+ _close_open_fd_range(3, local_max_fd, py_fds_to_keep);
+ }
+
/* This loop matches the Lib/os.py _execvpe()'s PATH search when */
/* given the executable_list generated by Lib/subprocess.py. */
saved_errno = 0;