Skip to content

Commit

Permalink
cgroups2: make a function declaration-less by moving it earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
robertswiecki committed Oct 4, 2023
1 parent c0e13ee commit 3d0bbf6
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions cgroup2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3d0bbf6

Please sign in to comment.