libprocessgroup: Use correct language for cgroups
Refer to cgroups and the cgroup hierarchy by their correct names. Bug: 301871933 Change-Id: Iebb3eac9363018e923773292786d01977c8763ae
This commit is contained in:
parent
599d979126
commit
a99e7d84cb
4 changed files with 15 additions and 14 deletions
|
@ -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);
|
||||
|
|
|
@ -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<DIR, decltype(&closedir)> uid(opendir(uid_path.c_str()), closedir);
|
||||
bool empty = true;
|
||||
if (uid != NULL) {
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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…
Reference in a new issue