diff options
author | Suren Baghdasaryan <surenb@google.com> | 2019-06-26 11:08:50 -0700 |
---|---|---|
committer | Suren Baghdasaryan <surenb@google.com> | 2019-06-26 11:35:11 -0700 |
commit | 25eb1bfadf0dc1ed1245e4e57f20cf816f4555c3 (patch) | |
tree | ee598a74f0abf8630df3298b4fbe42d40b096e75 /libprocessgroup/cgroup_map.cpp | |
parent | c0349199db745ee53e8d1133ddfce57fccc69cc7 (diff) |
Fix IsUsable to check for each controller separately
CgroupController::IsUsable is using a global static variable to store the
existence of the controller. That means the first controller existence
check would affect all other controllers. Fix this by making this variable
to be a member of CgroupController class so that each controller can check
for its existence independently of other controllers.
Fixes: aa1d54f0ccbb ("Remove ACgroupController_getFlags to fix API breakage")
Bug: 136020193
Test: adb shell cat /proc/$pid/task/*/cgroup" prints "cpuset:/top-app"
Test: for new launched activity process
Change-Id: I4741a9126ea494122d5b2b1a0c4d7252bff6025c
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Diffstat (limited to 'libprocessgroup/cgroup_map.cpp')
-rw-r--r-- | libprocessgroup/cgroup_map.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/libprocessgroup/cgroup_map.cpp b/libprocessgroup/cgroup_map.cpp index 9797d763f..20ae2be77 100644 --- a/libprocessgroup/cgroup_map.cpp +++ b/libprocessgroup/cgroup_map.cpp @@ -67,11 +67,14 @@ bool CgroupController::HasValue() const { return controller_ != nullptr; } -bool CgroupController::IsUsable() const { +bool CgroupController::IsUsable() { if (!HasValue()) return false; - static bool enabled = (access(GetProcsFilePath("", 0, 0).c_str(), F_OK) == 0); - return enabled; + if (state_ == UNKNOWN) { + state_ = access(GetProcsFilePath("", 0, 0).c_str(), F_OK) == 0 ? USABLE : MISSING; + } + + return state_ == USABLE; } std::string CgroupController::GetTasksFilePath(const std::string& rel_path) const { |