Merge "Revert "libprocessgroup: Add a function to remove only empty process groups"" into main

This commit is contained in:
Bart Van Assche 2023-11-18 17:02:44 +00:00 committed by Gerrit Code Review
commit ced62e53ed
2 changed files with 5 additions and 29 deletions

View file

@ -87,7 +87,6 @@ bool setProcessGroupSwappiness(uid_t uid, int initialPid, int swappiness);
bool setProcessGroupSoftLimit(uid_t uid, int initialPid, int64_t softLimitInBytes);
bool setProcessGroupLimit(uid_t uid, int initialPid, int64_t limitInBytes);
void removeAllProcessGroups(void);
void removeAllEmptyProcessGroups(void);
// Provides the path for an attribute in a specific process group

View file

@ -233,7 +233,7 @@ static int RemoveCgroup(const char* cgroup, uid_t uid, int pid, unsigned int ret
return ret;
}
static bool RemoveUidCgroups(const std::string& uid_path, bool empty_only) {
static bool RemoveEmptyUidCgroups(const std::string& uid_path) {
std::unique_ptr<DIR, decltype(&closedir)> uid(opendir(uid_path.c_str()), closedir);
bool empty = true;
if (uid != NULL) {
@ -248,21 +248,6 @@ static bool RemoveUidCgroups(const std::string& uid_path, bool empty_only) {
}
auto path = StringPrintf("%s/%s", uid_path.c_str(), dir->d_name);
if (empty_only) {
struct stat st;
auto procs_file = StringPrintf("%s/%s", path.c_str(),
PROCESSGROUP_CGROUP_PROCS_FILE);
if (stat(procs_file.c_str(), &st) == -1) {
PLOG(ERROR) << "Failed to get stats for " << procs_file;
continue;
}
if (st.st_size > 0) {
// skip non-empty groups
LOG(VERBOSE) << "Skipping non-empty group " << path;
empty = false;
continue;
}
}
LOG(VERBOSE) << "Removing " << path;
if (rmdir(path.c_str()) == -1) {
if (errno != EBUSY) {
@ -275,7 +260,9 @@ static bool RemoveUidCgroups(const std::string& uid_path, bool empty_only) {
return empty;
}
static void removeAllProcessGroupsInternal(bool empty_only) {
void removeAllEmptyProcessGroups() {
LOG(VERBOSE) << "removeAllEmptyProcessGroups()";
std::vector<std::string> cgroups;
std::string path, memcg_apps_path;
@ -302,7 +289,7 @@ static void removeAllProcessGroupsInternal(bool empty_only) {
}
auto path = StringPrintf("%s/%s", cgroup_root_path.c_str(), dir->d_name);
if (!RemoveUidCgroups(path, empty_only)) {
if (!RemoveEmptyUidCgroups(path)) {
LOG(VERBOSE) << "Skip removing " << path;
continue;
}
@ -315,16 +302,6 @@ static void removeAllProcessGroupsInternal(bool empty_only) {
}
}
void removeAllProcessGroups() {
LOG(VERBOSE) << "removeAllProcessGroups()";
removeAllProcessGroupsInternal(false);
}
void removeAllEmptyProcessGroups() {
LOG(VERBOSE) << "removeAllEmptyProcessGroups()";
removeAllProcessGroupsInternal(true);
}
/**
* Process groups are primarily created by the Zygote, meaning that uid/pid groups are created by
* the user root. Ownership for the newly created cgroup and all of its files must thus be