(self)
| 662 | t.close() |
| 663 | |
| 664 | def test_close_fds(self): |
| 665 | # guarantee some extra fds in our parent process that don't close on exec. |
| 666 | # we have to explicitly do this because at some point (I believe python 3.4), |
| 667 | # python started being more stringent with closing fds to prevent security |
| 668 | # vulnerabilities. python 2.7, for example, doesn't set CLOEXEC on |
| 669 | # tempfile.TemporaryFile()s |
| 670 | # |
| 671 | # https://www.python.org/dev/peps/pep-0446/ |
| 672 | tmp = [tempfile.TemporaryFile() for i in range(10)] |
| 673 | for t in tmp: |
| 674 | flags = fcntl.fcntl(t.fileno(), fcntl.F_GETFD) |
| 675 | flags &= ~fcntl.FD_CLOEXEC |
| 676 | fcntl.fcntl(t.fileno(), fcntl.F_SETFD, flags) |
| 677 | |
| 678 | py = create_tmp_test( |
| 679 | """ |
| 680 | import os |
| 681 | print(os.listdir("/dev/fd")) |
| 682 | """ |
| 683 | ) |
| 684 | out = python(py.name).strip() |
| 685 | self.assertEqual(out, "['0', '1', '2', '3']") |
| 686 | |
| 687 | for t in tmp: |
| 688 | t.close() |
| 689 | |
| 690 | def test_pass_fds(self): |
| 691 | # guarantee some extra fds in our parent process that don't close on exec. |
nothing calls this directly
no test coverage detected