]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #23458: Remove test_os.test_urandom_fd_non_inheritable()
authorVictor Stinner <victor.stinner@gmail.com>
Mon, 6 Apr 2015 21:39:47 +0000 (23:39 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Mon, 6 Apr 2015 21:39:47 +0000 (23:39 +0200)
os.urandom() only tries to make the os.random() file descriptor non
inheritable, but there is no guarantee. The test fails on too many operating
systems: Windows, OS X 10.5, OpenIndiana.

This issue is correctly fixed in Python 3.4 with the PEP 446. Upgrade to Python
3.4 is you need stronger guarantees.

Lib/test/subprocessdata/fd_status.py [deleted file]
Lib/test/test_os.py

diff --git a/Lib/test/subprocessdata/fd_status.py b/Lib/test/subprocessdata/fd_status.py
deleted file mode 100644 (file)
index 7d5c0e8..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-"""When called as a script, print a comma-separated list of the open
-file descriptors on stdout.
-
-Usage:
-fd_stats.py: check all file descriptors
-fd_status.py fd1 fd2 ...: check only specified file descriptors
-"""
-
-import errno
-import os
-import stat
-import sys
-
-if __name__ == "__main__":
-    fds = []
-    if len(sys.argv) == 1:
-        try:
-            _MAXFD = os.sysconf("SC_OPEN_MAX")
-        except:
-            _MAXFD = 256
-        test_fds = range(0, _MAXFD)
-    else:
-        test_fds = map(int, sys.argv[1:])
-    for fd in test_fds:
-        try:
-            st = os.fstat(fd)
-        except OSError as e:
-            if e.errno == errno.EBADF:
-                continue
-            raise
-        fds.append(fd)
-    print(','.join(map(str, fds)))
index d82ee58f1b44a389d2b82768f7acde02c4f62d1c..6c7ea7a58ec14363aa008711c8975b5ba79e93ea 100644 (file)
@@ -569,37 +569,6 @@ class URandomTests (unittest.TestCase):
         data2 = self.get_urandom_subprocess(16)
         self.assertNotEqual(data1, data2)
 
-    # os.urandom() doesn't use a file descriptor on Windows
-    @unittest.skipIf(sys.platform == "win32", "POSIX specific tests")
-    # FD_CLOEXEC is first supported on OS X 10.5
-    @test_support.requires_mac_ver(10, 5)
-    def test_urandom_fd_non_inheritable(self):
-        # Issue #23458: os.urandom() keeps a file descriptor open, but it
-        # must be non inheritable
-        fd_status = test_support.findfile("fd_status.py", subdir="subprocessdata")
-
-        # Need a two subprocesses because the Python test suite opens other
-        # inheritable file descriptors, whereas the test is specific to
-        # os.urandom() file descriptor
-        code = textwrap.dedent("""
-            import os
-            import subprocess
-            import sys
-
-            # Ensure that the /dev/urandom file descriptor is open
-            os.urandom(1)
-
-            exitcode = subprocess.call([sys.executable, %r],
-                                       close_fds=False)
-            sys.exit(exitcode)
-        """ % fd_status)
-
-        proc = subprocess.Popen([sys.executable, "-c", code],
-                                stdout=subprocess.PIPE, close_fds=True)
-        output, error = proc.communicate()
-        open_fds = set(map(int, output.rstrip().split(',')))
-        self.assertEqual(open_fds - set(range(3)), set())
-
 
 HAVE_GETENTROPY = (sysconfig.get_config_var('HAVE_GETENTROPY') == 1)