diff options
author | Suren Baghdasaryan <surenb@google.com> | 2019-06-26 15:49:23 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-06-26 15:49:23 -0700 |
commit | 8e3b94c2e296f1d23b49e1a61d20f3ebf8f417b5 (patch) | |
tree | b7bd059c85a046feea613cb249f952d4b84184cd | |
parent | 5dd50fdb9c9386371d3ebafacb04c0270a80d455 (diff) | |
parent | cb06c2b3769dc316f54b69ae316bbe2ec205bfce (diff) | |
download | system_core-8e3b94c2e296f1d23b49e1a61d20f3ebf8f417b5.tar.gz system_core-8e3b94c2e296f1d23b49e1a61d20f3ebf8f417b5.tar.bz2 system_core-8e3b94c2e296f1d23b49e1a61d20f3ebf8f417b5.zip |
Fix IsUsable to check for each controller separately
am: cb06c2b376
Change-Id: Id04ea4a5a208a307a7a2a3a6c801d38232921f36
-rw-r--r-- | libprocessgroup/cgroup_map.cpp | 9 | ||||
-rw-r--r-- | libprocessgroup/cgroup_map.h | 12 |
2 files changed, 16 insertions, 5 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 { diff --git a/libprocessgroup/cgroup_map.h b/libprocessgroup/cgroup_map.h index 935041242..427d71b40 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 { |