summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-12-13 22:30:19 -0800
committerZac Medico <zmedico@gentoo.org>2011-12-13 22:30:19 -0800
commit1a26bf9e433abff5f0b68f2a3b546eac732a359b (patch)
treeb71d1f0f944179e0a8faa470f0edf1fd280e6c01
parent3bcbe6b069687855fa3cc8f0e39be6c240ee3e3e (diff)
downloadportage-1a26bf9e433abff5f0b68f2a3b546eac732a359b.tar.gz
portage-1a26bf9e433abff5f0b68f2a3b546eac732a359b.tar.bz2
portage-1a26bf9e433abff5f0b68f2a3b546eac732a359b.zip
SpawnProcess: use /dev/null fd from subclass
-rw-r--r--pym/_emerge/SpawnProcess.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/pym/_emerge/SpawnProcess.py b/pym/_emerge/SpawnProcess.py
index 065146c75..84493fe42 100644
--- a/pym/_emerge/SpawnProcess.py
+++ b/pym/_emerge/SpawnProcess.py
@@ -39,16 +39,6 @@ class SpawnProcess(SubProcess):
if self.fd_pipes is None:
self.fd_pipes = {}
fd_pipes = self.fd_pipes
- fd_pipes.setdefault(0, sys.stdin.fileno())
- fd_pipes.setdefault(1, sys.stdout.fileno())
- fd_pipes.setdefault(2, sys.stderr.fileno())
-
- # flush any pending output
- for fd in fd_pipes.values():
- if fd == sys.stdout.fileno():
- sys.stdout.flush()
- if fd == sys.stderr.fileno():
- sys.stderr.flush()
self._files = self._files_dict()
files = self._files
@@ -62,22 +52,35 @@ class SpawnProcess(SubProcess):
logfile = self.logfile
null_input = None
- fd_pipes_orig = fd_pipes.copy()
- if self.background:
+ if not self.background or 0 in fd_pipes:
+ # Subclasses such as AbstractEbuildProcess may have already passed
+ # in a null file descriptor in fd_pipes, so use that when given.
+ pass
+ else:
# TODO: Use job control functions like tcsetpgrp() to control
# access to stdin. Until then, use /dev/null so that any
# attempts to read from stdin will immediately return EOF
# instead of blocking indefinitely.
null_input = open('/dev/null', 'rb')
fd_pipes[0] = null_input.fileno()
- else:
- fd_pipes[0] = fd_pipes_orig[0]
+
+ fd_pipes.setdefault(0, sys.stdin.fileno())
+ fd_pipes.setdefault(1, sys.stdout.fileno())
+ fd_pipes.setdefault(2, sys.stderr.fileno())
+
+ # flush any pending output
+ for fd in fd_pipes.values():
+ if fd == sys.stdout.fileno():
+ sys.stdout.flush()
+ if fd == sys.stderr.fileno():
+ sys.stderr.flush()
# WARNING: It is very important to use unbuffered mode here,
# in order to avoid issue 5380 with python3.
files.process = os.fdopen(master_fd, 'rb', 0)
if logfile is not None:
+ fd_pipes_orig = fd_pipes.copy()
fd_pipes[1] = slave_fd
fd_pipes[2] = slave_fd