Loading libprocessgroup/include/processgroup/processgroup.h +2 −1 Original line number Diff line number Diff line Loading @@ -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); Loading libprocessgroup/processgroup.cpp +10 −10 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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) { Loading Loading @@ -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) { Loading @@ -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; } Loading Loading @@ -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(); Loading Loading @@ -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; } } Loading @@ -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); Loading Loading @@ -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); } Loading libprocessgroup/setup/cgroup_map_write.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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); Loading libprocessgroup/task_profiles_test.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -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 += "/"; Loading Loading
libprocessgroup/include/processgroup/processgroup.h +2 −1 Original line number Diff line number Diff line Loading @@ -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); Loading
libprocessgroup/processgroup.cpp +10 −10 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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) { Loading Loading @@ -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) { Loading @@ -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; } Loading Loading @@ -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(); Loading Loading @@ -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; } } Loading @@ -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); Loading Loading @@ -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); } Loading
libprocessgroup/setup/cgroup_map_write.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading @@ -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); Loading
libprocessgroup/task_profiles_test.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -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 += "/"; Loading