fix mem clean in finishFromParent

This commit is contained in:
flaeyer 2021-10-14 12:12:46 +08:00
parent 5b82f51b8a
commit 26869e8956

View File

@ -81,14 +81,14 @@ static bool initNsFromParentMem(nsjconf_t* nsjconf, pid_t pid) {
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"));
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_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);