Revert "libprocessgroup: Combine all 3 ActivateControllers imple..."
Revert submission 3212512
Reason for revert: Droidmonitor created revert due to b/372273614. Will be verifying through ABTD before submission.
Reverted changes: /q/submissionid:3212512
Change-Id: I3dadc0b7bccfe28bb067a93df2acf2c3ea0f9920
diff --git a/libprocessgroup/cgroup_map.cpp b/libprocessgroup/cgroup_map.cpp
index 32bef13..8180ccf 100644
--- a/libprocessgroup/cgroup_map.cpp
+++ b/libprocessgroup/cgroup_map.cpp
@@ -194,6 +194,24 @@
return CgroupControllerWrapper(nullptr);
}
-bool CgroupMap::ActivateControllers(const std::string& path) const {
- return ::ActivateControllers(path, descriptors_);
+int CgroupMap::ActivateControllers(const std::string& path) const {
+ for (const auto& [name, descriptor] : descriptors_) {
+ const uint32_t flags = descriptor.controller()->flags();
+ const uint32_t max_activation_depth = descriptor.controller()->max_activation_depth();
+ const int depth = GetCgroupDepth(descriptor.controller()->path(), path);
+
+ if (flags & CGROUPRC_CONTROLLER_FLAG_NEEDS_ACTIVATION && depth < max_activation_depth) {
+ std::string str("+");
+ str.append(descriptor.controller()->name());
+ if (!WriteStringToFile(str, path + "/cgroup.subtree_control")) {
+ if (flags & CGROUPRC_CONTROLLER_FLAG_OPTIONAL) {
+ PLOG(WARNING) << "Activation of cgroup controller " << str
+ << " failed in path " << path;
+ } else {
+ return -errno;
+ }
+ }
+ }
+ }
+ return 0;
}