diff --git a/libprocessgroup/include/processgroup/processgroup.h b/libprocessgroup/include/processgroup/processgroup.h index a319c631f..9107838b8 100644 --- a/libprocessgroup/include/processgroup/processgroup.h +++ b/libprocessgroup/include/processgroup/processgroup.h @@ -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 diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index d352f0e34..b4482d096 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -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 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 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