summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2018-02-16 11:15:18 +0100
committerJürg Billeter <j@bitron.ch>2018-02-24 11:10:51 +0100
commitba823ce345bd7c7a292148d9ea582e90329f327b (patch)
treea65857739e3d3e1a3c8b9cff7170ce6f5735684e
parent32df086d28d85e049274228468a8276e44cc1bcc (diff)
downloadbuildstream-juerg/die-with-parent.tar.gz
sandbox/_sandboxbwrap.py: Use --die-with-parentjuerg/die-with-parent
This ensures subprocesses are cleaned up when the bwrap parent dies. This is available since bubblewrap 0.1.8. We skip the option if the host bwrap does not support it.
-rw-r--r--buildstream/_platform/linux.py21
-rw-r--r--buildstream/sandbox/_sandboxbwrap.py5
2 files changed, 26 insertions, 0 deletions
diff --git a/buildstream/_platform/linux.py b/buildstream/_platform/linux.py
index c180cc60a..9a2bcd356 100644
--- a/buildstream/_platform/linux.py
+++ b/buildstream/_platform/linux.py
@@ -36,6 +36,9 @@ class Linux(Platform):
self._user_ns_available = False
self.check_user_ns_available(context)
+
+ self.check_die_with_parent_available(context)
+
self._artifact_cache = OSTreeCache(context, enable_push=self._user_ns_available)
def check_user_ns_available(self, context):
@@ -69,6 +72,23 @@ class Linux(Platform):
detail="Some builds may not function due to lack of uid / gid 0, " +
"artifacts created will not be trusted for push purposes."))
+ def check_die_with_parent_available(self, context):
+
+ # bwrap supports --die-with-parent since 0.1.8.
+ # Let's check whether the host bwrap supports it.
+ bwrap = utils.get_host_tool('bwrap')
+
+ try:
+ subprocess.check_call([
+ bwrap,
+ '--ro-bind', '/', '/',
+ '--die-with-parent',
+ 'true'
+ ], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ self._die_with_parent_available = True
+ except subprocess.CalledProcessError:
+ self._die_with_parent_available = False
+
@property
def artifactcache(self):
return self._artifact_cache
@@ -76,4 +96,5 @@ class Linux(Platform):
def create_sandbox(self, *args, **kwargs):
# Inform the bubblewrap sandbox as to whether it can use user namespaces or not
kwargs['user_ns_available'] = self._user_ns_available
+ kwargs['die_with_parent_available'] = self._die_with_parent_available
return SandboxBwrap(*args, **kwargs)
diff --git a/buildstream/sandbox/_sandboxbwrap.py b/buildstream/sandbox/_sandboxbwrap.py
index cab178f0f..02f6ab30a 100644
--- a/buildstream/sandbox/_sandboxbwrap.py
+++ b/buildstream/sandbox/_sandboxbwrap.py
@@ -51,6 +51,7 @@ class SandboxBwrap(Sandbox):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user_ns_available = kwargs['user_ns_available']
+ self.die_with_parent_available = kwargs['die_with_parent_available']
def run(self, command, flags, *, cwd=None, env=None):
stdout, stderr = self._get_output()
@@ -84,6 +85,10 @@ class SandboxBwrap(Sandbox):
# are cleaned up when the bwrap process exits.
bwrap_command += ['--unshare-pid']
+ # Ensure subprocesses are cleaned up when the bwrap parent dies.
+ if self.die_with_parent_available:
+ bwrap_command += ['--die-with-parent']
+
# Add in the root filesystem stuff first.
#
# The rootfs is mounted as RW initially so that further mounts can be