summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-10-03 06:59:23 +0000
committerZac Medico <zmedico@gentoo.org>2009-10-03 06:59:23 +0000
commit0fdef36d3557ea3ee64a8982e66338db2ebbd1f8 (patch)
tree2ff370b358d24d1c9a7589d23bf498dd1376d00b
parent14ab0793efe3f8059ac29ce093b793b9b453d606 (diff)
downloadportage-0fdef36d3557ea3ee64a8982e66338db2ebbd1f8.tar.gz
portage-0fdef36d3557ea3ee64a8982e66338db2ebbd1f8.tar.bz2
portage-0fdef36d3557ea3ee64a8982e66338db2ebbd1f8.zip
Fix race condition when using a fork inside _test_pty_eof().
svn path=/main/trunk/; revision=14478
-rw-r--r--pym/portage/__init__.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 6f88f00fa..1469cd961 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -3768,8 +3768,6 @@ def _test_pty_eof():
# Simulate a subprocess writing some data to the
# 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,
@@ -3786,6 +3784,12 @@ def _test_pty_eof():
encoding='utf_8', errors='strict'))
os.close(slave_fd)
+ # If using a fork, we must wait for the child here,
+ # in order to avoid a race condition that would
+ # lead to inconsistent results.
+ if pid is not None:
+ os.waitpid(pid, 0)
+
master_file = os.fdopen(master_fd, 'rb')
eof = False
data = []
@@ -3815,8 +3819,6 @@ def _test_pty_eof():
data.append(_unicode_decode(buf.tostring(),
encoding='utf_8', errors='strict'))
- if pid is not None:
- os.waitpid(pid, 0)
master_file.close()
return test_string == ''.join(data)