summaryrefslogtreecommitdiffstats
path: root/py/mock
diff options
context:
space:
mode:
authorMike Bonnet <mikeb@redhat.com>2008-01-24 17:16:46 -0500
committerMichael E Brown <mebrown@michaels-house.net>2008-01-24 18:49:46 -0600
commitf1f47ae2bb7770c6ed072f779763c275a18f9828 (patch)
treeaf595968d93507c43be6f1c97bc563babc87ccc9 /py/mock
parent0fd7dd4e63e09671bb816510b3fde1555814e085 (diff)
downloadmock-f1f47ae2bb7770c6ed072f779763c275a18f9828.tar.gz
mock-f1f47ae2bb7770c6ed072f779763c275a18f9828.tar.xz
mock-f1f47ae2bb7770c6ed072f779763c275a18f9828.zip
set the current working directory in the chroot
This patch allows you to set the current working directory (in the chroot) before running a command with --chroot. This avoids the need to pass shell snippets ('cd /some/path && /run/cmd') to mock when running a command that expects to executed from a certain directory. It's useful when using --copyin to setup the environment before running a command. >From e4071d1d41a62ccf4461dfab958f9325edf30c97 Mon Sep 17 00:00:00 2001 From: Mike Bonnet <mikeb@redhat.com> Date: Thu, 24 Jan 2008 17:09:06 -0500 Subject: [PATCH] optionally set the current working directory (in the chroot) before running command with --chroot Signed-off-by: Michael E Brown <mebrown@michaels-house.net>
Diffstat (limited to 'py/mock')
-rw-r--r--py/mock/util.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/py/mock/util.py b/py/mock/util.py
index f93f98b..65cc995 100644
--- a/py/mock/util.py
+++ b/py/mock/util.py
@@ -201,6 +201,10 @@ def condChroot(chrootPath):
os.chroot(chrootPath)
uid.setresuid(saved['ruid'], saved['euid'])
+def condChdir(cwd):
+ if cwd is not None:
+ os.chdir(cwd)
+
def condDropPrivs(uid, gid):
if gid is not None:
os.setregid(gid, gid)
@@ -245,12 +249,12 @@ def logOutput(fds, logger, returnOutput=1, start=0, timeout=0):
# The "Not-as-complicated" version
#
decorate(traceLog())
-def do(command, shell=False, chrootPath=None, timeout=0, raiseExc=True, returnOutput=0, uid=None, gid=None, personality=None, *args, **kargs):
+def do(command, shell=False, chrootPath=None, cwd=None, timeout=0, raiseExc=True, returnOutput=0, uid=None, gid=None, personality=None, *args, **kargs):
logger = kargs.get("logger", getLog())
output = ""
start = time.time()
- preexec = ChildPreExec(personality, chrootPath, uid, gid)
+ preexec = ChildPreExec(personality, chrootPath, cwd, uid, gid)
try:
child = None
logger.debug("Executing command: %s" % command)
@@ -292,9 +296,10 @@ def do(command, shell=False, chrootPath=None, timeout=0, raiseExc=True, returnOu
return output
class ChildPreExec(object):
- def __init__(self, personality, chrootPath, uid, gid):
+ def __init__(self, personality, chrootPath, cwd, uid, gid):
self.personality = personality
self.chrootPath = chrootPath
+ self.cwd = cwd
self.uid = uid
self.gid = gid
@@ -303,4 +308,4 @@ class ChildPreExec(object):
condPersonality(self.personality)
condChroot(self.chrootPath)
condDropPrivs(self.uid, self.gid)
-
+ condChdir(self.cwd)