diff options
author | Michael E Brown <mebrown@michaels-house.net> | 2007-11-17 22:14:45 -0600 |
---|---|---|
committer | Michael E Brown <mebrown@michaels-house.net> | 2007-11-17 22:14:45 -0600 |
commit | 80466c5312be685597b12b641ed32a609cd9c111 (patch) | |
tree | 2dec0def2a515fd5213676eff44138afd06ce2a3 /src | |
parent | 41be2f7ec5b41e978e833f87883b92e37d42e136 (diff) | |
download | mock-80466c5312be685597b12b641ed32a609cd9c111.tar.gz mock-80466c5312be685597b12b641ed32a609cd9c111.tar.xz mock-80466c5312be685597b12b641ed32a609cd9c111.zip |
hand-code setarch to remove dep on /usr/bin/setarch
Diffstat (limited to 'src')
-rwxr-xr-x | src/mock.py | 19 | ||||
-rw-r--r-- | src/py-libs/backend.py | 27 | ||||
-rw-r--r-- | src/py-libs/util.py | 17 |
3 files changed, 41 insertions, 22 deletions
diff --git a/src/mock.py b/src/mock.py index 80f4f86..6cb4fd8 100755 --- a/src/mock.py +++ b/src/mock.py @@ -30,6 +30,12 @@ import sys import time from optparse import OptionParser +try: + import ctypes + have_ctypes = 1 +except ImportError: + have_ctypes = 0 + # all of the variables below are substituted by the build system __VERSION__="0.8.8" SYSCONFDIR="/usr/local/etc" @@ -118,7 +124,9 @@ def setup_default_config_opts(config_opts): config_opts['build_log_fmt_name'] = "unadorned" config_opts['root_log_fmt_name'] = "detailed" config_opts['state_log_fmt_name'] = "state" - config_opts['internal_setarch'] = True + config_opts['internal_setarch'] = False + if have_ctypes: + config_opts['internal_setarch'] = True # cleanup_on_* only take effect for separate --resultdir # config_opts provides fine-grained control. cmdline only has big hammer @@ -196,10 +204,6 @@ def set_config_opts_per_cmdline(config_opts, options): config_opts['cleanup_on_success'] = False config_opts['cleanup_on_failure'] = False - config_opts['setarch'] = "" - if config_opts['internal_setarch']: - config_opts['setarch'] = "setarch %s" % config_opts['target_arch'] - @traceLog(log) def warn_obsolete_config_options(config_opts): pass @@ -312,8 +316,11 @@ def main(retParams): chroot.init() chroot._mountall() try: + setarch = "" + if config_opts['internal_setarch'] and os.path.exists('/usr/bin/setarch'): + setarch = "/usr/bin/setarch %s" % config_opts['target_arch'] cmd = ' '.join(args[1:]) - os.system("PS1='mock-chroot> ' %s /usr/sbin/chroot %s %s" % (config_opts['setarch'], chroot.rootdir, cmd)) + os.system("PS1='mock-chroot> ' %s /usr/sbin/chroot %s %s" % (setarch, chroot.rootdir, cmd)) finally: chroot._umountall() diff --git a/src/py-libs/backend.py b/src/py-libs/backend.py index 492e8a0..c3887c4 100644 --- a/src/py-libs/backend.py +++ b/src/py-libs/backend.py @@ -32,11 +32,7 @@ class Root(object): self.uidManager = uidManager self._hooks = {} self.chrootWasCleaned = False - self.preExistingDeps = "" - self.setarch = config['setarch'] - if config['internal_setarch']: - self.preExistingDeps = "/usr/bin/setarch " self.sharedRootName = config['root'] root = self.sharedRootName @@ -49,6 +45,10 @@ class Root(object): self.homedir = config['chroothome'] self.builddir = os.path.join(self.homedir, 'build') + self.personality = None + if config['internal_setarch']: + self.personality = config['target_arch'] + # result dir if not config.has_key('resultdir'): self.resultdir = os.path.join(self.basedir, 'result') @@ -274,7 +274,7 @@ class Root(object): @traceLog(moduleLog) def doChroot(self, command, env="", *args, **kargs): """execute given command in root""" - return mock.util.do( command, chrootPath=self.rootdir, *args, **kargs ) + return mock.util.do( command, personality=self.personality, chrootPath=self.rootdir, *args, **kargs ) @traceLog(moduleLog) def yumInstall(self, *srpms): @@ -336,9 +336,8 @@ class Root(object): # install srpm os.environ["HOME"] = self.homedir # Completely/Permanently drop privs while running the following: - mock.util.do( + self.doChroot( "rpm -Uvh --nodeps %s" % (srpmChrootFilename,), - chrootPath=self.rootdir, uidManager=self.uidManager, uid=self.chrootuid, gid=self.chrootgid, @@ -353,9 +352,8 @@ class Root(object): chrootspec = spec.replace(self.rootdir, '') # get rid of rootdir prefix self.root_log.info("about to drop to unpriv mode.") # Completely/Permanently drop privs while running the following: - mock.util.do( + self.doChroot( "rpmbuild -bs --target %s --nodeps %s" % (self.target_arch, chrootspec), - chrootPath=self.rootdir, logger=self.build_log, timeout=timeout, uidManager=self.uidManager, uid=self.chrootuid, @@ -375,13 +373,12 @@ class Root(object): # tell caching we are building self._callHooks('prebuild') - mock.util.do( - "%s rpmbuild -bb --target %s --nodeps %s" % (self.setarch, self.target_arch, chrootspec), - chrootPath=self.rootdir, + self.doChroot( + "rpmbuild -bb --target %s --nodeps %s" % (self.target_arch, chrootspec), + logger=self.build_log, timeout=timeout, uidManager=self.uidManager, uid=self.chrootuid, gid=self.chrootgid, - logger=self.build_log, timeout=timeout, ) bd_out = self.rootdir + self.builddir @@ -444,11 +441,11 @@ class Root(object): def _yum(self, cmd, returnOutput=0): """use yum to install packages/package groups into the chroot""" # mock-helper yum --installroot=rootdir cmd - cmd = '%s %s --installroot %s %s' % (self.setarch, self.yum_path, self.rootdir, cmd) + cmd = '%s --installroot %s %s' % (self.yum_path, self.rootdir, cmd) self.root_log.info(cmd) try: self._callHooks("preyum") - output = mock.util.do(cmd, returnOutput=returnOutput) + output = mock.util.do(cmd, returnOutput=returnOutput, personality=self.personality) self._callHooks("postyum") return output except mock.exception.Error, e: diff --git a/src/py-libs/util.py b/src/py-libs/util.py index b3f8706..8553bac 100644 --- a/src/py-libs/util.py +++ b/src/py-libs/util.py @@ -182,6 +182,20 @@ def chomp(line): else: return line +personality_defs = {} +personality_defs['x86_64'] = 0x0000 +personality_defs['i386'] = 0x0008 +# ... need to add ppc/ppc64... + +@traceLog(log) +def condPersonality(per): + if per is None: return + import ctypes + _libc = ctypes.cdll.LoadLibrary("libc.so.6") + _libc.personality.argtypes = [ctypes.c_ulong] + _libc.personality.restype = ctypes.c_int + _libc.personality(personality_defs.get(per, 0x00)) + # logger = # output = [1|0] # chrootPath @@ -189,7 +203,7 @@ def chomp(line): # Warning: this is the function from hell. :( # @traceLog(log) -def do(command, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uidManager=None, uid=None, gid=None, *args, **kargs): +def do(command, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uidManager=None, uid=None, gid=None, personality=None, *args, **kargs): """execute given command outside of chroot""" logger = kargs.get("logger", log) @@ -253,6 +267,7 @@ def do(command, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uidMa # can kill our children os.setpgrp() + condPersonality(personality) condChroot(chrootPath, uidManager) condDropPrivs(uidManager, uid, gid) |