From a99e7d84cb7d6b7eab5402800ea5ba71a8fe1fd5 Mon Sep 17 00:00:00 2001 From: "T.J. Mercier" Date: Fri, 27 Oct 2023 17:29:01 +0000 Subject: [PATCH] libprocessgroup: Use correct language for cgroups Refer to cgroups and the cgroup hierarchy by their correct names. Bug: 301871933 Change-Id: Iebb3eac9363018e923773292786d01977c8763ae --- .../include/processgroup/processgroup.h | 3 ++- libprocessgroup/processgroup.cpp | 20 +++++++++---------- libprocessgroup/setup/cgroup_map_write.cpp | 4 ++-- libprocessgroup/task_profiles_test.cpp | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/libprocessgroup/include/processgroup/processgroup.h b/libprocessgroup/include/processgroup/processgroup.h index 5c43224ab321..a319c631f70f 100644 --- a/libprocessgroup/include/processgroup/processgroup.h +++ b/libprocessgroup/include/processgroup/processgroup.h @@ -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); diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index 3fa43f8adfc6..0b1794eb8138 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -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); @@ -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 uid(opendir(uid_path.c_str()), closedir); bool empty = true; if (uid != NULL) { @@ -279,7 +279,7 @@ void removeAllProcessGroupsInternal(bool empty_only) { std::vector 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) { @@ -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; } @@ -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(); @@ -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; } } @@ -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); @@ -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); } @@ -664,4 +664,4 @@ bool isProfileValidForProcess(const std::string& profile_name, int uid, int pid) } return tp->IsValidForProcess(uid, pid); -} \ No newline at end of file +} diff --git a/libprocessgroup/setup/cgroup_map_write.cpp b/libprocessgroup/setup/cgroup_map_write.cpp index fbeedf99c84b..4e44c91befe0 100644 --- a/libprocessgroup/setup/cgroup_map_write.cpp +++ b/libprocessgroup/setup/cgroup_map_write.cpp @@ -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) { @@ -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); diff --git a/libprocessgroup/task_profiles_test.cpp b/libprocessgroup/task_profiles_test.cpp index 99d819a7cc4c..b17e695e562b 100644 --- a/libprocessgroup/task_profiles_test.cpp +++ b/libprocessgroup/task_profiles_test.cpp @@ -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 += "/";