Fix IsUsable to check for each controller separately am: cb06c2b376

am: 8e3b94c2e2

Change-Id: I9ad1ef75ee5ccdfdfdcf42ccfcdd7fb56e867b5a
This commit is contained in:
Suren Baghdasaryan 2019-06-26 18:15:26 -07:00 committed by android-build-merger
commit 2f10322b2c
2 changed files with 16 additions and 5 deletions

View File

@ -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 {

View File

@ -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 {