From: Zac Medico Date: Wed, 14 Dec 2011 06:30:19 +0000 (-0800) Subject: SpawnProcess: use /dev/null fd from subclass X-Git-Tag: v2.2.0_alpha81~7 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1a26bf9e433abff5f0b68f2a3b546eac732a359b;p=portage.git SpawnProcess: use /dev/null fd from subclass --- 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