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>
diff --git a/libprocessgroup/cgroup_map.h b/libprocessgroup/cgroup_map.h
index 9350412..427d71b 100644
--- a/libprocessgroup/cgroup_map.h
+++ b/libprocessgroup/cgroup_map.h
@@ -31,20 +31,28 @@
class CgroupController {
public:
// Does not own controller
- explicit CgroupController(const ACgroupController* controller) : controller_(controller) {}
+ explicit CgroupController(const ACgroupController* controller)
+ : controller_(controller), state_(UNKNOWN) {}
uint32_t version() const;
const char* name() const;
const char* path() const;
bool HasValue() const;
- bool IsUsable() const;
+ bool IsUsable();
std::string GetTasksFilePath(const std::string& path) const;
std::string GetProcsFilePath(const std::string& path, uid_t uid, pid_t pid) const;
bool GetTaskGroup(int tid, std::string* group) const;
private:
+ enum ControllerState {
+ UNKNOWN = 0,
+ USABLE = 1,
+ MISSING = 2,
+ };
+
const ACgroupController* controller_ = nullptr;
+ ControllerState state_;
};
class CgroupMap {