diff options
author | 2019-06-27 15:17:39 -0700 | |
---|---|---|
committer | 2019-06-27 15:17:39 -0700 | |
commit | 160982a742ad9a4ad5318bbf19f74598b157a7ca (patch) | |
tree | c21e48fd355165fe80e83590d278851aed9d395a | |
parent | Disable memory swapping and add a memory limit test (diff) |
Fix error when setting swap limit on a system that has it disabled
The error happens when either CONFIG_MEMCG_SWAP or
CONFIG_MEMCG_SWAP_ENABLED is disabled in the kernel.
-rw-r--r-- | snekbox/nsjail.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/snekbox/nsjail.py b/snekbox/nsjail.py index b9c4fc7..b79ec9e 100644 --- a/snekbox/nsjail.py +++ b/snekbox/nsjail.py @@ -71,9 +71,15 @@ class NsJail: with (mem / "memory.limit_in_bytes").open("w", encoding="utf=8") as f: f.write(str(MEM_MAX)) - # Swap limit is specified as the sum of the memory and swap limits. - with (mem / "memory.memsw.limit_in_bytes").open("w", encoding="utf=8") as f: - f.write(str(MEM_MAX)) + try: + # Swap limit is specified as the sum of the memory and swap limits. + with (mem / "memory.memsw.limit_in_bytes").open("w", encoding="utf=8") as f: + f.write(str(MEM_MAX)) + except PermissionError: + log.info( + "Failed to disable memory swapping in the cgroup. " + "This is probably because CONFIG_MEMCG_SWAP_ENABLED is unset." + ) @staticmethod def _parse_log(log_lines: Iterable[str]): |