diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-10-03 06:10:58 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-10-03 06:10:58 +0000 |
commit | 14ab0793efe3f8059ac29ce093b793b9b453d606 (patch) | |
tree | 5299ea08b30e0f8d4efa9506739ef525518c7113 | |
parent | 0b178b09286a3ffe1cb83bdf915ee32567095ee8 (diff) | |
download | portage-14ab0793efe3f8059ac29ce093b793b9b453d606.tar.gz portage-14ab0793efe3f8059ac29ce093b793b9b453d606.tar.bz2 portage-14ab0793efe3f8059ac29ce093b793b9b453d606.zip |
Don't use a fork inside _test_pty_eof() because it gives inconsistent results.
svn path=/main/trunk/; revision=14477
-rw-r--r-- | pym/portage/__init__.py | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index bf0362f9f..6f88f00fa 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -3746,6 +3746,8 @@ def _test_pty_eof(): Raises an EnvironmentError from openpty() if it fails. """ + use_fork = False + import array, fcntl, pty, select, termios test_string = 2 * "blah blah blah\n" test_string = _unicode_decode(test_string, @@ -3765,17 +3767,23 @@ def _test_pty_eof(): termios.tcsetattr(slave_fd, termios.TCSANOW, mode) # Simulate a subprocess writing some data to the - # slave end of the pipe, and then exiting. Do a - # real fork here since otherwise os.close(slave_fd) - # would block on some platforms such as Darwin. - pids = process.spawn_bash(_unicode_encode("echo -n '%s'" % test_string, - encoding='utf_8', errors='strict'), env=os.environ, - fd_pipes={0:sys.stdin.fileno(), 1:slave_fd, 2:slave_fd}, - returnpid=True) - if isinstance(pids, int): - os.close(master_fd) - os.close(slave_fd) - raise EnvironmentError('spawn failed') + # slave end of the pipe, and then exiting. + # Using a fork here gave inconsistent results, + # so it's disabled now. + pid = None + if use_fork: + pids = process.spawn_bash(_unicode_encode("echo -n '%s'" % test_string, + encoding='utf_8', errors='strict'), env=os.environ, + fd_pipes={0:sys.stdin.fileno(), 1:slave_fd, 2:slave_fd}, + returnpid=True) + if isinstance(pids, int): + os.close(master_fd) + os.close(slave_fd) + raise EnvironmentError('spawn failed') + pid = pids[0] + else: + os.write(slave_fd, _unicode_encode(test_string, + encoding='utf_8', errors='strict')) os.close(slave_fd) master_file = os.fdopen(master_fd, 'rb') @@ -3807,7 +3815,8 @@ def _test_pty_eof(): data.append(_unicode_decode(buf.tostring(), encoding='utf_8', errors='strict')) - os.waitpid(pids[0], 0) + if pid is not None: + os.waitpid(pid, 0) master_file.close() return test_string == ''.join(data) |