When SpawnProcess._start() spawns a process in the background, use /dev/null
authorZac Medico <zmedico@gentoo.org>
Thu, 17 Jul 2008 04:20:12 +0000 (04:20 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 17 Jul 2008 04:20:12 +0000 (04:20 -0000)
so that any attempts to read from stdin will immediately return EOF instead
of blocking indefinitely. TODO: Use job control functions like tcsetpgrp()
to control access to stdin.

svn path=/main/trunk/; revision=11093

pym/_emerge/__init__.py

index 1373d3abb05fa86ab86662a2fba4819879afe440..13df0d8f5dd690cdc3d1c83d1e0c170617522aec 100644 (file)
@@ -2045,11 +2045,21 @@ class SpawnProcess(SubProcess):
                fcntl.fcntl(master_fd, fcntl.F_SETFL,
                        fcntl.fcntl(master_fd, fcntl.F_GETFL) | os.O_NONBLOCK)
 
+               null_input = None
+               fd_pipes_orig = fd_pipes.copy()
+               if self.background:
+                       # 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]
+
                files.process = os.fdopen(master_fd, 'r')
                if logfile is not None:
 
-                       fd_pipes_orig = fd_pipes.copy()
-                       fd_pipes[0] = fd_pipes_orig[0]
                        fd_pipes[1] = slave_fd
                        fd_pipes[2] = slave_fd
 
@@ -2086,6 +2096,8 @@ class SpawnProcess(SubProcess):
                retval = self._spawn(self.args, **kwargs)
 
                os.close(slave_fd)
+               if null_input is not None:
+                       null_input.close()
 
                if isinstance(retval, int):
                        # spawn failed