Merge "Revert "libprocessgroup: Add a function to remove only empty process groups"" into main
diff --git a/libprocessgroup/include/processgroup/processgroup.h b/libprocessgroup/include/processgroup/processgroup.h
index a319c63..9107838 100644
--- a/libprocessgroup/include/processgroup/processgroup.h
+++ b/libprocessgroup/include/processgroup/processgroup.h
@@ -87,7 +87,6 @@
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
diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp
index d352f0e..b4482d0 100644
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -233,7 +233,7 @@
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 @@
}
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 @@
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 @@
}
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 @@
}
}
-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