SpawnProcess: avoid fd_pipes interference
authorZac Medico <zmedico@gentoo.org>
Tue, 15 Jan 2013 14:12:27 +0000 (06:12 -0800)
committerZac Medico <zmedico@gentoo.org>
Tue, 15 Jan 2013 14:12:27 +0000 (06:12 -0800)
This fixes a random collision that can occur with FileDigester,
triggering malfunction and a KeyError.

pym/_emerge/SpawnProcess.py

index 5d0fcf6dd6feb2735ed7ab6860945fa462c8acfe..9c754add54499a4484fa67f13645de1e7961e741 100644 (file)
@@ -76,8 +76,14 @@ class SpawnProcess(SubProcess):
 
                else:
                        # Create a dummy pipe so the scheduler can monitor
-                       # the process from inside a poll() loop.
-                       fd_pipes[self._dummy_pipe_fd] = slave_fd
+                       # the process from inside a poll() loop. Ensure that
+                       # it doesn't interfere with a random fd that's already
+                       # in fd_pipes though (as least FileDigester can pass
+                       # in a random fd returned from os.pipe()).
+                       unique_dummy_fd = self._dummy_pipe_fd
+                       while unique_dummy_fd in fd_pipes:
+                               unique_dummy_fd += 1
+                       fd_pipes[unique_dummy_fd] = slave_fd
                        if self.background:
                                fd_pipes[1] = slave_fd
                                fd_pipes[2] = slave_fd