diff options
-rw-r--r-- | pym/_emerge/EbuildProcess.py | 10 | ||||
-rw-r--r-- | pym/portage/package/ebuild/doebuild.py | 64 |
2 files changed, 41 insertions, 33 deletions
diff --git a/pym/_emerge/EbuildProcess.py b/pym/_emerge/EbuildProcess.py index 84a8d1b61..50edaa16d 100644 --- a/pym/_emerge/EbuildProcess.py +++ b/pym/_emerge/EbuildProcess.py @@ -15,6 +15,12 @@ class EbuildProcess(AbstractEbuildProcess): __slots__ = ('actionmap',) + _unsandboxed_phases = frozenset([ + "clean", "cleanrm", "config", + "help", "info", "postinst", + "preinst", "pretend", "postrm", + "prerm", "setup"]) + def _start(self): # Don't open the log file during the clean phase since the # open file can result in an nfs lock on $T/build.log which @@ -25,6 +31,10 @@ class EbuildProcess(AbstractEbuildProcess): def _spawn(self, args, **kwargs): self.settings["EBUILD_PHASE"] = self.phase + if self.phase in self._unsandboxed_phases: + kwargs['free'] = True + if self.phase == 'depend': + kwargs['droppriv'] = 'userpriv' in self.settings.features actionmap = self.actionmap if actionmap is None: actionmap = _spawn_actionmap(self.settings) diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py index c4a782c4e..195bfdd4f 100644 --- a/pym/portage/package/ebuild/doebuild.py +++ b/pym/portage/package/ebuild/doebuild.py @@ -432,12 +432,6 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, # Only cache it if the above stray files test succeeds. _doebuild_manifest_cache = mf - # Note: PORTAGE_BIN_PATH may differ from the global - # constant when portage is reinstalling itself. - portage_bin_path = mysettings["PORTAGE_BIN_PATH"] - ebuild_sh_binary = os.path.join(portage_bin_path, - os.path.basename(EBUILD_SH_BINARY)) - logfile=None builddir_lock = None tmpdir = None @@ -477,21 +471,16 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, use_cache, mydbapi) if mydo in clean_phases: - retval = spawn(_shell_quote(ebuild_sh_binary) + " clean", - mysettings, debug=debug, fd_pipes=fd_pipes, free=1, - logfile=None, returnpid=returnpid) - return retval + return _spawn_phase(mydo, mysettings, + fd_pipes=fd_pipes, returnpid=returnpid) restrict = set(mysettings.get('PORTAGE_RESTRICT', '').split()) # get possible slot information from the deps file if mydo == "depend": writemsg("!!! DEBUG: dbkey: %s\n" % str(dbkey), 2) - droppriv = "userpriv" in mysettings.features if returnpid: - mypids = spawn(_shell_quote(ebuild_sh_binary) + " depend", - mysettings, fd_pipes=fd_pipes, returnpid=True, - droppriv=droppriv) - return mypids + return _spawn_phase(mydo, mysettings, + fd_pipes=fd_pipes, returnpid=returnpid) elif isinstance(dbkey, dict): mysettings["dbkey"] = "" pr, pw = os.pipe() @@ -500,9 +489,8 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, 1:sys.stdout.fileno(), 2:sys.stderr.fileno(), 9:pw} - mypids = spawn(_shell_quote(ebuild_sh_binary) + " depend", - mysettings, - fd_pipes=fd_pipes, returnpid=True, droppriv=droppriv) + mypids = _spawn_phase(mydo, mysettings, returnpid=True, + fd_pipes=fd_pipes) os.close(pw) # belongs exclusively to the child process now f = os.fdopen(pr, 'rb') for k, v in zip(auxdbkeys, @@ -530,9 +518,8 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, mysettings["dbkey"] = \ os.path.join(mysettings.depcachedir, "aux_db_key_temp") - return spawn(_shell_quote(ebuild_sh_binary) + " depend", - mysettings, - droppriv=droppriv) + return _spawn_phase(mydo, mysettings, + fd_pipes=fd_pipes, returnpid=returnpid) # Validate dependency metadata here to ensure that ebuilds with invalid # data are never installed via the ebuild command. Don't bother when @@ -579,20 +566,9 @@ def doebuild(myebuild, mydo, myroot, mysettings, debug=0, listonly=0, # the sandbox -- and stop now. if mydo in ("config", "help", "info", "postinst", "preinst", "pretend", "postrm", "prerm", "setup"): - if returnpid: - return spawn( - _shell_quote(ebuild_sh_binary) + " " + mydo, - mysettings, debug=debug, free=1, logfile=logfile, + return _spawn_phase(mydo, mysettings, fd_pipes=fd_pipes, returnpid=returnpid) - task_scheduler = TaskScheduler() - ebuild_phase = EbuildPhase(background=False, - phase=mydo, scheduler=task_scheduler.sched_iface, - settings=mysettings) - task_scheduler.add(ebuild_phase) - task_scheduler.run() - return ebuild_phase.returncode - mycpv = "/".join((mysettings["CATEGORY"], mysettings["PF"])) emerge_skip_distfiles = returnpid @@ -1096,6 +1072,28 @@ def spawn(mystring, mysettings, debug=0, free=0, droppriv=0, sesandbox=0, fakero return proc.returncode +def _spawn_phase(phase, settings, **kwargs): + if kwargs.get('returnpid'): + portage_bin_path = settings["PORTAGE_BIN_PATH"] + ebuild_sh_binary = os.path.join(portage_bin_path, + os.path.basename(EBUILD_SH_BINARY)) + if phase == 'cleanrm': + ebuild_sh_arg = 'clean' + else: + ebuild_sh_arg = phase + if phase == 'depend': + kwargs['droppriv'] = 'userpriv' in settings.features + return spawn("%s %s" % (_shell_quote(ebuild_sh_binary), ebuild_sh_arg), + settings, **kwargs) + + task_scheduler = TaskScheduler() + ebuild_phase = EbuildPhase(background=False, + phase=phase, scheduler=task_scheduler.sched_iface, + settings=settings) + task_scheduler.add(ebuild_phase) + task_scheduler.run() + return ebuild_phase.returncode + # parse actionmap to spawn ebuild with the appropriate args def spawnebuild(mydo, actionmap, mysettings, debug, alwaysdep=0, logfile=None, fd_pipes=None, returnpid=False): |