diff options
author | 2021-02-26 18:21:11 +0100 | |
---|---|---|
committer | 2021-02-26 18:21:11 +0100 | |
commit | 59a1bf423f63275aa02781d307cb0fad1361f31e (patch) | |
tree | 16fae78aa63a5330b5354641e2eaef3e56c4c5e3 | |
parent | Merge pull request #91 from python-discord/dynamic-parent-cgroups (diff) | |
parent | Remove all child cgroups before removing parents (diff) |
Merge pull request #94 from python-discord/recursive-remove-cgroups
Remove all child cgroups before removing parents
-rw-r--r-- | snekbox/nsjail.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/snekbox/nsjail.py b/snekbox/nsjail.py index 3235ee0..06c3154 100644 --- a/snekbox/nsjail.py +++ b/snekbox/nsjail.py @@ -224,6 +224,18 @@ class NsJail: log.info(f"nsjail return code: {returncode}") + # If we hit a cgroup limit then there is a chance the nsjail cgroups did not + # get removed. If we don't remove them then when we try remove the parents + # we will get a "Device or resource busy" error. + + children = [] + + children.extend(Path(self.config.cgroup_mem_mount, cgroup).glob("NSJAIL.*")) + children.extend(Path(self.config.cgroup_pids_mount, cgroup).glob("NSJAIL.*")) + + for child in children: + child.rmdir() + # Remove the dynamically created cgroups once we're done Path(self.config.cgroup_mem_mount, cgroup).rmdir() Path(self.config.cgroup_pids_mount, cgroup).rmdir() |