1 |
commit: 1a26bf9e433abff5f0b68f2a3b546eac732a359b |
2 |
Author: Zac Medico <zmedico <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Dec 14 06:30:19 2011 +0000 |
4 |
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Dec 14 06:30:19 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=1a26bf9e |
7 |
|
8 |
SpawnProcess: use /dev/null fd from subclass |
9 |
|
10 |
--- |
11 |
pym/_emerge/SpawnProcess.py | 31 +++++++++++++++++-------------- |
12 |
1 files changed, 17 insertions(+), 14 deletions(-) |
13 |
|
14 |
diff --git a/pym/_emerge/SpawnProcess.py b/pym/_emerge/SpawnProcess.py |
15 |
index 065146c..84493fe 100644 |
16 |
--- a/pym/_emerge/SpawnProcess.py |
17 |
+++ b/pym/_emerge/SpawnProcess.py |
18 |
@@ -39,16 +39,6 @@ class SpawnProcess(SubProcess): |
19 |
if self.fd_pipes is None: |
20 |
self.fd_pipes = {} |
21 |
fd_pipes = self.fd_pipes |
22 |
- fd_pipes.setdefault(0, sys.stdin.fileno()) |
23 |
- fd_pipes.setdefault(1, sys.stdout.fileno()) |
24 |
- fd_pipes.setdefault(2, sys.stderr.fileno()) |
25 |
- |
26 |
- # flush any pending output |
27 |
- for fd in fd_pipes.values(): |
28 |
- if fd == sys.stdout.fileno(): |
29 |
- sys.stdout.flush() |
30 |
- if fd == sys.stderr.fileno(): |
31 |
- sys.stderr.flush() |
32 |
|
33 |
self._files = self._files_dict() |
34 |
files = self._files |
35 |
@@ -62,22 +52,35 @@ class SpawnProcess(SubProcess): |
36 |
logfile = self.logfile |
37 |
|
38 |
null_input = None |
39 |
- fd_pipes_orig = fd_pipes.copy() |
40 |
- if self.background: |
41 |
+ if not self.background or 0 in fd_pipes: |
42 |
+ # Subclasses such as AbstractEbuildProcess may have already passed |
43 |
+ # in a null file descriptor in fd_pipes, so use that when given. |
44 |
+ pass |
45 |
+ else: |
46 |
# TODO: Use job control functions like tcsetpgrp() to control |
47 |
# access to stdin. Until then, use /dev/null so that any |
48 |
# attempts to read from stdin will immediately return EOF |
49 |
# instead of blocking indefinitely. |
50 |
null_input = open('/dev/null', 'rb') |
51 |
fd_pipes[0] = null_input.fileno() |
52 |
- else: |
53 |
- fd_pipes[0] = fd_pipes_orig[0] |
54 |
+ |
55 |
+ fd_pipes.setdefault(0, sys.stdin.fileno()) |
56 |
+ fd_pipes.setdefault(1, sys.stdout.fileno()) |
57 |
+ fd_pipes.setdefault(2, sys.stderr.fileno()) |
58 |
+ |
59 |
+ # flush any pending output |
60 |
+ for fd in fd_pipes.values(): |
61 |
+ if fd == sys.stdout.fileno(): |
62 |
+ sys.stdout.flush() |
63 |
+ if fd == sys.stderr.fileno(): |
64 |
+ sys.stderr.flush() |
65 |
|
66 |
# WARNING: It is very important to use unbuffered mode here, |
67 |
# in order to avoid issue 5380 with python3. |
68 |
files.process = os.fdopen(master_fd, 'rb', 0) |
69 |
if logfile is not None: |
70 |
|
71 |
+ fd_pipes_orig = fd_pipes.copy() |
72 |
fd_pipes[1] = slave_fd |
73 |
fd_pipes[2] = slave_fd |