1 |
Author: zmedico |
2 |
Date: 2009-10-03 06:59:23 +0000 (Sat, 03 Oct 2009) |
3 |
New Revision: 14478 |
4 |
|
5 |
Modified: |
6 |
main/trunk/pym/portage/__init__.py |
7 |
Log: |
8 |
Fix race condition when using a fork inside _test_pty_eof(). |
9 |
|
10 |
|
11 |
Modified: main/trunk/pym/portage/__init__.py |
12 |
=================================================================== |
13 |
--- main/trunk/pym/portage/__init__.py 2009-10-03 06:10:58 UTC (rev 14477) |
14 |
+++ main/trunk/pym/portage/__init__.py 2009-10-03 06:59:23 UTC (rev 14478) |
15 |
@@ -3768,8 +3768,6 @@ |
16 |
|
17 |
# Simulate a subprocess writing some data to the |
18 |
# slave end of the pipe, and then exiting. |
19 |
- # Using a fork here gave inconsistent results, |
20 |
- # so it's disabled now. |
21 |
pid = None |
22 |
if use_fork: |
23 |
pids = process.spawn_bash(_unicode_encode("echo -n '%s'" % test_string, |
24 |
@@ -3786,6 +3784,12 @@ |
25 |
encoding='utf_8', errors='strict')) |
26 |
os.close(slave_fd) |
27 |
|
28 |
+ # If using a fork, we must wait for the child here, |
29 |
+ # in order to avoid a race condition that would |
30 |
+ # lead to inconsistent results. |
31 |
+ if pid is not None: |
32 |
+ os.waitpid(pid, 0) |
33 |
+ |
34 |
master_file = os.fdopen(master_fd, 'rb') |
35 |
eof = False |
36 |
data = [] |
37 |
@@ -3815,8 +3819,6 @@ |
38 |
data.append(_unicode_decode(buf.tostring(), |
39 |
encoding='utf_8', errors='strict')) |
40 |
|
41 |
- if pid is not None: |
42 |
- os.waitpid(pid, 0) |
43 |
master_file.close() |
44 |
|
45 |
return test_string == ''.join(data) |