Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f9f14436 authored by T.J. Mercier's avatar T.J. Mercier Committed by Gerrit Code Review
Browse files

Merge changes I9f850003,Idb270068,I39df9814 into main

* changes:
  libprocessgroup: Remove unused CgroupMap::SetupCgroups declaration
  libprocessgroup: Rename files a_cgroup_controller.cpp, a_cgroup_file.cpp
  libprocessgroup: Rename CgroupController -> CgroupControllerWrapper
parents fc28da24 7c94e5b2
Loading
Loading
Loading
Loading
+17 −17
Original line number Diff line number Diff line
@@ -38,26 +38,26 @@ static constexpr const char* CGROUP_PROCS_FILE = "/cgroup.procs";
static constexpr const char* CGROUP_TASKS_FILE = "/tasks";
static constexpr const char* CGROUP_TASKS_FILE_V2 = "/cgroup.threads";

uint32_t CgroupController::version() const {
uint32_t CgroupControllerWrapper::version() const {
    CHECK(HasValue());
    return ACgroupController_getVersion(controller_);
}

const char* CgroupController::name() const {
const char* CgroupControllerWrapper::name() const {
    CHECK(HasValue());
    return ACgroupController_getName(controller_);
}

const char* CgroupController::path() const {
const char* CgroupControllerWrapper::path() const {
    CHECK(HasValue());
    return ACgroupController_getPath(controller_);
}

bool CgroupController::HasValue() const {
bool CgroupControllerWrapper::HasValue() const {
    return controller_ != nullptr;
}

bool CgroupController::IsUsable() {
bool CgroupControllerWrapper::IsUsable() {
    if (!HasValue()) return false;

    if (state_ == UNKNOWN) {
@@ -72,7 +72,7 @@ bool CgroupController::IsUsable() {
    return state_ == USABLE;
}

std::string CgroupController::GetTasksFilePath(const std::string& rel_path) const {
std::string CgroupControllerWrapper::GetTasksFilePath(const std::string& rel_path) const {
    std::string tasks_path = path();

    if (!rel_path.empty()) {
@@ -81,7 +81,7 @@ std::string CgroupController::GetTasksFilePath(const std::string& rel_path) cons
    return (version() == 1) ? tasks_path + CGROUP_TASKS_FILE : tasks_path + CGROUP_TASKS_FILE_V2;
}

std::string CgroupController::GetProcsFilePath(const std::string& rel_path, uid_t uid,
std::string CgroupControllerWrapper::GetProcsFilePath(const std::string& rel_path, uid_t uid,
                                                      pid_t pid) const {
    std::string proc_path(path());
    proc_path.append("/").append(rel_path);
@@ -91,7 +91,7 @@ std::string CgroupController::GetProcsFilePath(const std::string& rel_path, uid_
    return proc_path.append(CGROUP_PROCS_FILE);
}

bool CgroupController::GetTaskGroup(pid_t tid, std::string* group) const {
bool CgroupControllerWrapper::GetTaskGroup(pid_t tid, std::string* group) const {
    std::string file_name = StringPrintf("/proc/%d/cgroup", tid);
    std::string content;
    if (!android::base::ReadFileToString(file_name, &content)) {
@@ -175,40 +175,40 @@ void CgroupMap::Print() const {
    }
}

CgroupController CgroupMap::FindController(const std::string& name) const {
CgroupControllerWrapper CgroupMap::FindController(const std::string& name) const {
    if (!loaded_) {
        LOG(ERROR) << "CgroupMap::FindController called for [" << getpid()
                   << "] failed, RC file was not initialized properly";
        return CgroupController(nullptr);
        return CgroupControllerWrapper(nullptr);
    }

    auto controller_count = ACgroupFile_getControllerCount();
    for (uint32_t i = 0; i < controller_count; ++i) {
        const ACgroupController* controller = ACgroupFile_getController(i);
        if (name == ACgroupController_getName(controller)) {
            return CgroupController(controller);
            return CgroupControllerWrapper(controller);
        }
    }

    return CgroupController(nullptr);
    return CgroupControllerWrapper(nullptr);
}

CgroupController CgroupMap::FindControllerByPath(const std::string& path) const {
CgroupControllerWrapper CgroupMap::FindControllerByPath(const std::string& path) const {
    if (!loaded_) {
        LOG(ERROR) << "CgroupMap::FindControllerByPath called for [" << getpid()
                   << "] failed, RC file was not initialized properly";
        return CgroupController(nullptr);
        return CgroupControllerWrapper(nullptr);
    }

    auto controller_count = ACgroupFile_getControllerCount();
    for (uint32_t i = 0; i < controller_count; ++i) {
        const ACgroupController* controller = ACgroupFile_getController(i);
        if (StartsWith(path, ACgroupController_getPath(controller))) {
            return CgroupController(controller);
            return CgroupControllerWrapper(controller);
        }
    }

    return CgroupController(nullptr);
    return CgroupControllerWrapper(nullptr);
}

int CgroupMap::ActivateControllers(const std::string& path) const {
+4 −7
Original line number Diff line number Diff line
@@ -23,10 +23,10 @@
#include <android/cgrouprc.h>

// Convenient wrapper of an ACgroupController pointer.
class CgroupController {
class CgroupControllerWrapper {
  public:
    // Does not own controller
    explicit CgroupController(const ACgroupController* controller)
    explicit CgroupControllerWrapper(const ACgroupController* controller)
        : controller_(controller) {}

    uint32_t version() const;
@@ -53,12 +53,9 @@ class CgroupController {

class CgroupMap {
  public:
    // Selinux policy ensures only init process can successfully use this function
    static bool SetupCgroups();

    static CgroupMap& GetInstance();
    CgroupController FindController(const std::string& name) const;
    CgroupController FindControllerByPath(const std::string& path) const;
    CgroupControllerWrapper FindController(const std::string& name) const;
    CgroupControllerWrapper FindControllerByPath(const std::string& path) const;
    int ActivateControllers(const std::string& path) const;

  private:
+2 −2
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ cc_library {
        symbol_file: "libcgrouprc.map.txt",
    },
    srcs: [
        "cgroup_controller.cpp",
        "cgroup_file.cpp",
        "a_cgroup_controller.cpp",
        "a_cgroup_file.cpp",
    ],
    cflags: [
        "-Wall",
Loading