summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2012-01-21 22:39:29 (GMT)
committerGregory P. Smith <greg@krypto.org>2012-01-21 22:39:29 (GMT)
commitd635af5a61897e6246bfb1ddf7e4d496bfd1121d (patch)
tree96f1aefab41799ff7337c65e1c5dc21064bb5ba7 /Lib
parente961bd49342f875280d0336b328e5d748200e9e1 (diff)
parent8facece99a5917077833c85c726a699ee7a374f6 (diff)
downloadcpython-d635af5a61897e6246bfb1ddf7e4d496bfd1121d.zip
cpython-d635af5a61897e6246bfb1ddf7e4d496bfd1121d.tar.gz
cpython-d635af5a61897e6246bfb1ddf7e4d496bfd1121d.tar.bz2
Fixes issue #8052: The posix subprocess module's close_fds behavior was
suboptimal by closing all possible file descriptors rather than just the open ones in the child process before exec(). It now closes only the open fds when it is possible to safely determine what those are.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_subprocess.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 6c22901..d508b8f 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1392,6 +1392,11 @@ class POSIXProcessTestCase(BaseTestCase):
self.addCleanup(os.close, fds[1])
open_fds = set(fds)
+ # add a bunch more fds
+ for _ in range(9):
+ fd = os.open("/dev/null", os.O_RDONLY)
+ self.addCleanup(os.close, fd)
+ open_fds.add(fd)
p = subprocess.Popen([sys.executable, fd_status],
stdout=subprocess.PIPE, close_fds=False)
@@ -1410,6 +1415,19 @@ class POSIXProcessTestCase(BaseTestCase):
"Some fds were left open")
self.assertIn(1, remaining_fds, "Subprocess failed")
+ # Keep some of the fd's we opened open in the subprocess.
+ # This tests _posixsubprocess.c's proper handling of fds_to_keep.
+ fds_to_keep = set(open_fds.pop() for _ in range(8))
+ p = subprocess.Popen([sys.executable, fd_status],
+ stdout=subprocess.PIPE, close_fds=True,
+ pass_fds=())
+ output, ignored = p.communicate()
+ remaining_fds = set(map(int, output.split(b',')))
+
+ self.assertFalse(remaining_fds & fds_to_keep & open_fds,
+ "Some fds not in pass_fds were left open")
+ self.assertIn(1, remaining_fds, "Subprocess failed")
+
# Mac OS X Tiger (10.4) has a kernel bug: sometimes, the file
# descriptor of a pipe closed in the parent process is valid in the
# child process according to fstat(), but the mode of the file