Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Merge "libprocessgroup: Use correct language for cgroups" into main
Browse files Browse the repository at this point in the history
  • Loading branch information
T.J. Mercier authored and Gerrit Code Review committed Nov 6, 2023
2 parents ef9e7f8 + a99e7d8 commit d79ad66
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion libprocessgroup/include/processgroup/processgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

__BEGIN_DECLS

static constexpr const char* CGROUPV2_CONTROLLER_NAME = "cgroup2";
static constexpr const char* CGROUPV2_HIERARCHY_NAME = "cgroup2";
[[deprecated]] static constexpr const char* CGROUPV2_CONTROLLER_NAME = "cgroup2";

bool CgroupsAvailable();
bool CgroupGetControllerPath(const std::string& cgroup_name, std::string* path);
Expand Down
20 changes: 10 additions & 10 deletions libprocessgroup/processgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static std::string ConvertUidPidToPath(const char* cgroup, uid_t uid, int pid) {
return StringPrintf("%s/uid_%u/pid_%d", cgroup, uid, pid);
}

static int RemoveProcessGroup(const char* cgroup, uid_t uid, int pid, unsigned int retries) {
static int RemoveCgroup(const char* cgroup, uid_t uid, int pid, unsigned int retries) {
int ret = 0;
auto uid_pid_path = ConvertUidPidToPath(cgroup, uid, pid);

Expand All @@ -233,7 +233,7 @@ static int RemoveProcessGroup(const char* cgroup, uid_t uid, int pid, unsigned i
return ret;
}

static bool RemoveUidProcessGroups(const std::string& uid_path, bool empty_only) {
static bool RemoveUidCgroups(const std::string& uid_path, bool empty_only) {
std::unique_ptr<DIR, decltype(&closedir)> uid(opendir(uid_path.c_str()), closedir);
bool empty = true;
if (uid != NULL) {
Expand Down Expand Up @@ -279,7 +279,7 @@ void removeAllProcessGroupsInternal(bool empty_only) {
std::vector<std::string> cgroups;
std::string path, memcg_apps_path;

if (CgroupGetControllerPath(CGROUPV2_CONTROLLER_NAME, &path)) {
if (CgroupGetControllerPath(CGROUPV2_HIERARCHY_NAME, &path)) {
cgroups.push_back(path);
}
if (CgroupGetMemcgAppsPath(&memcg_apps_path) && memcg_apps_path != path) {
Expand All @@ -302,7 +302,7 @@ void removeAllProcessGroupsInternal(bool empty_only) {
}

auto path = StringPrintf("%s/%s", cgroup_root_path.c_str(), dir->d_name);
if (!RemoveUidProcessGroups(path, empty_only)) {
if (!RemoveUidCgroups(path, empty_only)) {
LOG(VERBOSE) << "Skip removing " << path;
continue;
}
Expand Down Expand Up @@ -461,7 +461,7 @@ static int KillProcessGroup(uid_t uid, int initialPid, int signal, int retries)

std::string hierarchy_root_path;
if (CgroupsAvailable()) {
CgroupGetControllerPath(CGROUPV2_CONTROLLER_NAME, &hierarchy_root_path);
CgroupGetControllerPath(CGROUPV2_HIERARCHY_NAME, &hierarchy_root_path);
}
const char* cgroup = hierarchy_root_path.c_str();

Expand Down Expand Up @@ -511,12 +511,12 @@ static int KillProcessGroup(uid_t uid, int initialPid, int signal, int retries)
}

// 400 retries correspond to 2 secs max timeout
int err = RemoveProcessGroup(cgroup, uid, initialPid, 400);
int err = RemoveCgroup(cgroup, uid, initialPid, 400);

if (isMemoryCgroupSupported() && UsePerAppMemcg()) {
std::string memcg_apps_path;
if (CgroupGetMemcgAppsPath(&memcg_apps_path) &&
RemoveProcessGroup(memcg_apps_path.c_str(), uid, initialPid, 400) < 0) {
RemoveCgroup(memcg_apps_path.c_str(), uid, initialPid, 400) < 0) {
return -1;
}
}
Expand All @@ -543,7 +543,7 @@ int killProcessGroupOnce(uid_t uid, int initialPid, int signal) {
int sendSignalToProcessGroup(uid_t uid, int initialPid, int signal) {
std::string hierarchy_root_path;
if (CgroupsAvailable()) {
CgroupGetControllerPath(CGROUPV2_CONTROLLER_NAME, &hierarchy_root_path);
CgroupGetControllerPath(CGROUPV2_HIERARCHY_NAME, &hierarchy_root_path);
}
const char* cgroup = hierarchy_root_path.c_str();
return DoKillProcessGroupOnce(cgroup, uid, initialPid, signal);
Expand Down Expand Up @@ -617,7 +617,7 @@ int createProcessGroup(uid_t uid, int initialPid, bool memControl) {
}

std::string cgroup;
CgroupGetControllerPath(CGROUPV2_CONTROLLER_NAME, &cgroup);
CgroupGetControllerPath(CGROUPV2_HIERARCHY_NAME, &cgroup);
return createProcessGroupInternal(uid, initialPid, cgroup, true);
}

Expand Down Expand Up @@ -664,4 +664,4 @@ bool isProfileValidForProcess(const std::string& profile_name, int uid, int pid)
}

return tp->IsValidForProcess(uid, pid);
}
}
4 changes: 2 additions & 2 deletions libprocessgroup/setup/cgroup_map_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static bool ReadDescriptorsFromFile(const std::string& file_name,
if (root.isMember("Cgroups2")) {
const Json::Value& cgroups2 = root["Cgroups2"];
std::string root_path = cgroups2["Path"].asString();
MergeCgroupToDescriptors(descriptors, cgroups2, CGROUPV2_CONTROLLER_NAME, "", 2);
MergeCgroupToDescriptors(descriptors, cgroups2, CGROUPV2_HIERARCHY_NAME, "", 2);

const Json::Value& childGroups = cgroups2["Controllers"];
for (Json::Value::ArrayIndex i = 0; i < childGroups.size(); ++i) {
Expand Down Expand Up @@ -358,7 +358,7 @@ static bool SetupCgroup(const CgroupDescriptor& descriptor) {
const format::CgroupController* controller = descriptor.controller();

if (controller->version() == 2) {
if (!strcmp(controller->name(), CGROUPV2_CONTROLLER_NAME)) {
if (!strcmp(controller->name(), CGROUPV2_HIERARCHY_NAME)) {
return MountV2CgroupController(descriptor);
} else {
return ActivateV2CgroupController(descriptor);
Expand Down
2 changes: 1 addition & 1 deletion libprocessgroup/task_profiles_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ProfileAttributeMock : public IProfileAttribute {
}
bool GetPathForTask(int tid, std::string* path) const override {
#ifdef __ANDROID__
CHECK(CgroupGetControllerPath(CGROUPV2_CONTROLLER_NAME, path));
CHECK(CgroupGetControllerPath(CGROUPV2_HIERARCHY_NAME, path));
CHECK_GT(path->length(), 0);
if (path->rbegin()[0] != '/') {
*path += "/";
Expand Down

0 comments on commit d79ad66

Please sign in to comment.