diff options
author | flaeyer <a@oi.al> | 2021-10-14 12:12:46 +0800 |
---|---|---|
committer | flaeyer <a@oi.al> | 2021-10-14 12:12:46 +0800 |
commit | 26869e8956a173510119399b130089f2c04ac364 (patch) | |
tree | d38df1b56d76eac0f8a12b6243b90736768dc853 | |
parent | 5b82f51b8ae9c28fa90886ce60b1b16b37727a47 (diff) | |
download | nsjail-26869e8956a173510119399b130089f2c04ac364.tar.gz |
fix mem clean in finishFromParent
-rw-r--r-- | cgroup.cc | 24 |
1 files changed, 12 insertions, 12 deletions
@@ -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); |