From eb547b4c1538ead1006a9184981369979afff82c Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 23 Dec 2008 18:53:13 +0000 Subject: [PATCH] Register for poll events before forking, in order to avoid potential race conditions in SpawnProcess._start() and EbuildMetadataPhase._start(). Hopefully this solves hung poll calls with defunct ebuild.sh processes, reported on solaris systems by Fabian Groffen . svn path=/main/trunk/; revision=12285 --- pym/_emerge/__init__.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index a22440c93..78715bad5 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -2175,6 +2175,10 @@ class SpawnProcess(SubProcess): kwargs["returnpid"] = True kwargs.pop("logfile", None) + self._reg_id = self.scheduler.register(files.process.fileno(), + PollConstants.POLLIN, output_handler) + self._registered = True + retval = self._spawn(self.args, **kwargs) os.close(slave_fd) @@ -2183,8 +2187,7 @@ class SpawnProcess(SubProcess): if isinstance(retval, int): # spawn failed - for f in files.values(): - f.close() + self._unregister() self.returncode = retval self.wait() return @@ -2192,10 +2195,6 @@ class SpawnProcess(SubProcess): self.pid = retval[0] portage.process.spawned_pids.remove(self.pid) - self._reg_id = self.scheduler.register(files.process.fileno(), - PollConstants.POLLIN, output_handler) - self._registered = True - def _pipe(self, fd_pipes): """ @type fd_pipes: dict @@ -2840,6 +2839,12 @@ class EbuildMetadataPhase(SubProcess): fd_pipes[self._metadata_fd] = slave_fd + self._raw_metadata = [] + files.ebuild = os.fdopen(master_fd, 'r') + self._reg_id = self.scheduler.register(files.ebuild.fileno(), + PollConstants.POLLIN, self._output_handler) + self._registered = True + retval = portage.doebuild(ebuild_path, "depend", settings["ROOT"], settings, debug, mydbapi=self.portdb, tree="porttree", @@ -2849,7 +2854,7 @@ class EbuildMetadataPhase(SubProcess): if isinstance(retval, int): # doebuild failed before spawning - os.close(master_fd) + self._unregister() self.returncode = retval self.wait() return @@ -2857,12 +2862,6 @@ class EbuildMetadataPhase(SubProcess): self.pid = retval[0] portage.process.spawned_pids.remove(self.pid) - self._raw_metadata = [] - files.ebuild = os.fdopen(master_fd, 'r') - self._reg_id = self.scheduler.register(files.ebuild.fileno(), - PollConstants.POLLIN, self._output_handler) - self._registered = True - def _output_handler(self, fd, event): files = self._files self._raw_metadata.append(files.ebuild.read()) -- 2.26.2