summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-05-22 16:20:30 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-05-22 16:20:30 +0100
commit52995d06857e1631406c367ab68a8a9cdf05243a (patch)
treeea0b6e88128973bbcdfc0e710da294096384c0a2
parentf5a11bf026ab9c82a70422560a19908bb0e602cd (diff)
downloadsandboxlib-52995d06857e1631406c367ab68a8a9cdf05243a.tar.gz
chroot: Handle failure better
-rw-r--r--sandboxlib/chroot.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/sandboxlib/chroot.py b/sandboxlib/chroot.py
index 157b9fe..8495df1 100644
--- a/sandboxlib/chroot.py
+++ b/sandboxlib/chroot.py
@@ -44,10 +44,18 @@ def run_sandbox(rootfs_path, command, cwd=None, extra_env=None):
# 'subprocess' module.
# FIXME: you gotta be root for this one.
- os.chroot(rootfs_path)
-
- result = subprocess.call(command, cwd=cwd, env=env)
- os._exit(result)
+ try:
+ try:
+ os.chroot(rootfs_path)
+ except OSError as e:
+ raise RuntimeError("Unable to chroot: %s" % e)
+
+ result = subprocess.call(command, cwd=cwd, env=env)
+ except Exception as e:
+ print("ERROR: %s" % e)
+ result = 255
+ finally:
+ os._exit(result)
else:
# Parent process. Wait for child to exit.
os.waitpid(pid, 0)