aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflaeyer <a@oi.al>2021-10-14 12:12:46 +0800
committerflaeyer <a@oi.al>2021-10-14 12:12:46 +0800
commit26869e8956a173510119399b130089f2c04ac364 (patch)
treed38df1b56d76eac0f8a12b6243b90736768dc853
parent5b82f51b8ae9c28fa90886ce60b1b16b37727a47 (diff)
downloadnsjail-26869e8956a173510119399b130089f2c04ac364.tar.gz
fix mem clean in finishFromParent
-rw-r--r--cgroup.cc24
1 files changed, 12 insertions, 12 deletions
diff --git a/cgroup.cc b/cgroup.cc
index 3df35c1..a984122 100644
--- a/cgroup.cc
+++ b/cgroup.cc
@@ -79,17 +79,17 @@ static bool initNsFromParentMem(nsjconf_t* nsjconf, pid_t pid) {
RETURN_ON_FAILURE(writeToCgroup(
mem_cgroup_path + "/memory.oom_control", "0", "memory cgroup oom control"));
- if (nsjconf->cgroup_mem_max > (size_t)0) {
- std::string mem_max_str = std::to_string(nsjconf->cgroup_mem_max);
- RETURN_ON_FAILURE(writeToCgroup(
- mem_cgroup_path + "/memory.limit_in_bytes", mem_max_str, "memory cgroup max limit"));
- }
-
- if (nsjconf->cgroup_mem_memsw_max > (size_t)0) {
- std::string mem_memsw_max_str = std::to_string(nsjconf->cgroup_mem_memsw_max);
- RETURN_ON_FAILURE(writeToCgroup(
- mem_cgroup_path + "/memory.memsw.limit_in_bytes", mem_memsw_max_str, "memory+Swap cgroup max limit"));
- }
+ if (nsjconf->cgroup_mem_max > (size_t)0) {
+ std::string mem_max_str = std::to_string(nsjconf->cgroup_mem_max);
+ RETURN_ON_FAILURE(writeToCgroup(mem_cgroup_path + "/memory.limit_in_bytes",
+ mem_max_str, "memory cgroup max limit"));
+ }
+
+ if (nsjconf->cgroup_mem_memsw_max > (size_t)0) {
+ std::string mem_memsw_max_str = std::to_string(nsjconf->cgroup_mem_memsw_max);
+ RETURN_ON_FAILURE(writeToCgroup(mem_cgroup_path + "/memory.memsw.limit_in_bytes",
+ mem_memsw_max_str, "memory+Swap cgroup max limit"));
+ }
return addPidToTaskList(mem_cgroup_path, pid);
}
@@ -167,7 +167,7 @@ static void removeCgroup(const std::string& cgroup_path) {
}
void finishFromParent(nsjconf_t* nsjconf, pid_t pid) {
- if (nsjconf->cgroup_mem_max != (size_t)0) {
+ if (nsjconf->cgroup_mem_max != (size_t)0 || nsjconf->cgroup_mem_memsw_max != (size_t)0) {
std::string mem_cgroup_path = nsjconf->cgroup_mem_mount + '/' +
nsjconf->cgroup_mem_parent + "/NSJAIL." +
std::to_string(pid);