summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-06-17 12:14:10 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-06-17 12:14:10 +0100
commit8aa1da46a85f8775889e8674f90b224430196c9e (patch)
treefea3a2484f0b78c991594638fd4f4c7f9fa2b364
parent19ddeaafc678110dd6d9429fb11a57825f72650a (diff)
downloadsandboxlib-8aa1da46a85f8775889e8674f90b224430196c9e.tar.gz
chroot: Change directory to '/' after calling os.chroot()
This fixes https://github.com/CodethinkLabs/sandboxlib/issues/6 where passing a relative path for 'cwd' caused an error. I had assumed that os.chroot() reset the current working directory itself, since the `chroot` program does, but apparently not.
-rw-r--r--sandboxlib/chroot.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/sandboxlib/chroot.py b/sandboxlib/chroot.py
index 6adaa06..c0f662b 100644
--- a/sandboxlib/chroot.py
+++ b/sandboxlib/chroot.py
@@ -167,6 +167,9 @@ def run_command_in_chroot(pipe, stdout, stderr, extra_mounts, chroot_path,
except OSError as e:
raise RuntimeError("Unable to chroot: %s" % e)
+ # This is important in case 'cwd' is a relative path.
+ os.chdir('/')
+
if cwd is not None:
try:
os.chdir(cwd)