diff --git a/cgroup2.cc b/cgroup2.cc index 215e177..e3a73e1 100644 --- a/cgroup2.cc +++ b/cgroup2.cc @@ -41,7 +41,17 @@ namespace cgroup2 { -static bool addPidToProcList(const std::string &cgroup_path, pid_t pid); +static bool addPidToProcList(const std::string &cgroup_path, pid_t pid) { + std::string pid_str = std::to_string(pid); + + LOG_D("Adding pid='%s' to cgroup.procs", pid_str.c_str()); + if (!util::writeBufToFile((cgroup_path + "/cgroup.procs").c_str(), pid_str.c_str(), + pid_str.length(), O_WRONLY)) { + LOG_W("Could not update cgroup.procs"); + return false; + } + return true; +} static std::string getCgroupPath(nsjconf_t *nsjconf, pid_t pid) { return nsjconf->cgroupv2_mount + "/NSJAIL." + std::to_string(pid); @@ -114,18 +124,6 @@ static bool writeToCgroup( return true; } -static bool addPidToProcList(const std::string &cgroup_path, pid_t pid) { - std::string pid_str = std::to_string(pid); - - LOG_D("Adding pid='%s' to cgroup.procs", pid_str.c_str()); - if (!util::writeBufToFile((cgroup_path + "/cgroup.procs").c_str(), pid_str.c_str(), - pid_str.length(), O_WRONLY)) { - LOG_W("Could not update cgroup.procs"); - return false; - } - return true; -} - static void removeCgroup(const std::string &cgroup_path) { LOG_D("Remove '%s'", cgroup_path.c_str()); if (rmdir(cgroup_path.c_str()) == -1) {