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

Commit 4b84ff9b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge changes I6fbbb329,I80a7c0a3 am: 5d1a8717 am: 7bb209eb

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1972101

Change-Id: Id0221f17f972f4ae4a9f15dfa5957197a57ed5de
parents afd4a9b3 7bb209eb
Loading
Loading
Loading
Loading
+25 −0
Original line number Original line Diff line number Diff line
@@ -397,6 +397,14 @@ Result<void> Service::ExecStart() {
    return {};
    return {};
}
}


static void ClosePipe(const std::array<int, 2>* pipe) {
    for (const auto fd : *pipe) {
        if (fd >= 0) {
            close(fd);
        }
    }
}

Result<void> Service::Start() {
Result<void> Service::Start() {
    auto reboot_on_failure = make_scope_guard([this] {
    auto reboot_on_failure = make_scope_guard([this] {
        if (on_failure_reboot_target_) {
        if (on_failure_reboot_target_) {
@@ -428,6 +436,12 @@ Result<void> Service::Start() {
        return {};
        return {};
    }
    }


    std::unique_ptr<std::array<int, 2>, decltype(&ClosePipe)> pipefd(new std::array<int, 2>{-1, -1},
                                                                     ClosePipe);
    if (pipe(pipefd->data()) < 0) {
        return ErrnoError() << "pipe()";
    }

    bool needs_console = (flags_ & SVC_CONSOLE);
    bool needs_console = (flags_ & SVC_CONSOLE);
    if (needs_console) {
    if (needs_console) {
        if (proc_attr_.console.empty()) {
        if (proc_attr_.console.empty()) {
@@ -532,6 +546,13 @@ Result<void> Service::Start() {
            LOG(ERROR) << "failed to write pid to files: " << result.error();
            LOG(ERROR) << "failed to write pid to files: " << result.error();
        }
        }


        // Wait until the cgroups have been created and until the cgroup controllers have been
        // activated.
        if (std::byte byte; read((*pipefd)[0], &byte, 1) < 0) {
            PLOG(ERROR) << "failed to read from notification channel";
        }
        pipefd.reset();

        if (task_profiles_.size() > 0 && !SetTaskProfiles(getpid(), task_profiles_)) {
        if (task_profiles_.size() > 0 && !SetTaskProfiles(getpid(), task_profiles_)) {
            LOG(ERROR) << "failed to set task profiles";
            LOG(ERROR) << "failed to set task profiles";
        }
        }
@@ -618,6 +639,10 @@ Result<void> Service::Start() {
        LmkdRegister(name_, proc_attr_.uid, pid_, oom_score_adjust_);
        LmkdRegister(name_, proc_attr_.uid, pid_, oom_score_adjust_);
    }
    }


    if (write((*pipefd)[1], "", 1) < 0) {
        return ErrnoError() << "sending notification failed";
    }

    NotifyStateChange("running");
    NotifyStateChange("running");
    reboot_on_failure.Disable();
    reboot_on_failure.Disable();
    return {};
    return {};
+2 −2
Original line number Original line Diff line number Diff line
@@ -85,7 +85,7 @@ bool CgroupGetControllerFromPath(const std::string& path, std::string* cgroup_na


bool CgroupGetAttributePath(const std::string& attr_name, std::string* path) {
bool CgroupGetAttributePath(const std::string& attr_name, std::string* path) {
    const TaskProfiles& tp = TaskProfiles::GetInstance();
    const TaskProfiles& tp = TaskProfiles::GetInstance();
    const ProfileAttribute* attr = tp.GetAttribute(attr_name);
    const IProfileAttribute* attr = tp.GetAttribute(attr_name);


    if (attr == nullptr) {
    if (attr == nullptr) {
        return false;
        return false;
@@ -100,7 +100,7 @@ bool CgroupGetAttributePath(const std::string& attr_name, std::string* path) {


bool CgroupGetAttributePathForTask(const std::string& attr_name, int tid, std::string* path) {
bool CgroupGetAttributePathForTask(const std::string& attr_name, int tid, std::string* path) {
    const TaskProfiles& tp = TaskProfiles::GetInstance();
    const TaskProfiles& tp = TaskProfiles::GetInstance();
    const ProfileAttribute* attr = tp.GetAttribute(attr_name);
    const IProfileAttribute* attr = tp.GetAttribute(attr_name);


    if (attr == nullptr) {
    if (attr == nullptr) {
        return false;
        return false;
+3 −1
Original line number Original line Diff line number Diff line
@@ -112,6 +112,8 @@ bool FdCacheHelper::IsAppDependentPath(const std::string& path) {
    return path.find("<uid>", 0) != std::string::npos || path.find("<pid>", 0) != std::string::npos;
    return path.find("<uid>", 0) != std::string::npos || path.find("<pid>", 0) != std::string::npos;
}
}


IProfileAttribute::~IProfileAttribute() = default;

void ProfileAttribute::Reset(const CgroupController& controller, const std::string& file_name) {
void ProfileAttribute::Reset(const CgroupController& controller, const std::string& file_name) {
    controller_ = controller;
    controller_ = controller;
    file_name_ = file_name;
    file_name_ = file_name;
@@ -726,7 +728,7 @@ TaskProfile* TaskProfiles::GetProfile(const std::string& name) const {
    return nullptr;
    return nullptr;
}
}


const ProfileAttribute* TaskProfiles::GetAttribute(const std::string& name) const {
const IProfileAttribute* TaskProfiles::GetAttribute(const std::string& name) const {
    auto iter = attributes_.find(name);
    auto iter = attributes_.find(name);


    if (iter != attributes_.end()) {
    if (iter != attributes_.end()) {
+19 −9
Original line number Original line Diff line number Diff line
@@ -26,16 +26,26 @@
#include <android-base/unique_fd.h>
#include <android-base/unique_fd.h>
#include <cgroup_map.h>
#include <cgroup_map.h>


class ProfileAttribute {
class IProfileAttribute {
  public:
    virtual ~IProfileAttribute() = 0;
    virtual void Reset(const CgroupController& controller, const std::string& file_name) = 0;
    virtual const CgroupController* controller() const = 0;
    virtual const std::string& file_name() const = 0;
    virtual bool GetPathForTask(int tid, std::string* path) const = 0;
};

class ProfileAttribute : public IProfileAttribute {
  public:
  public:
    ProfileAttribute(const CgroupController& controller, const std::string& file_name)
    ProfileAttribute(const CgroupController& controller, const std::string& file_name)
        : controller_(controller), file_name_(file_name) {}
        : controller_(controller), file_name_(file_name) {}
    ~ProfileAttribute() = default;


    const CgroupController* controller() const { return &controller_; }
    const CgroupController* controller() const override { return &controller_; }
    const std::string& file_name() const { return file_name_; }
    const std::string& file_name() const override { return file_name_; }
    void Reset(const CgroupController& controller, const std::string& file_name);
    void Reset(const CgroupController& controller, const std::string& file_name) override;


    bool GetPathForTask(int tid, std::string* path) const;
    bool GetPathForTask(int tid, std::string* path) const override;


  private:
  private:
    CgroupController controller_;
    CgroupController controller_;
@@ -88,14 +98,14 @@ class SetTimerSlackAction : public ProfileAction {
// Set attribute profile element
// Set attribute profile element
class SetAttributeAction : public ProfileAction {
class SetAttributeAction : public ProfileAction {
  public:
  public:
    SetAttributeAction(const ProfileAttribute* attribute, const std::string& value)
    SetAttributeAction(const IProfileAttribute* attribute, const std::string& value)
        : attribute_(attribute), value_(value) {}
        : attribute_(attribute), value_(value) {}


    bool ExecuteForProcess(uid_t uid, pid_t pid) const override;
    bool ExecuteForProcess(uid_t uid, pid_t pid) const override;
    bool ExecuteForTask(int tid) const override;
    bool ExecuteForTask(int tid) const override;


  private:
  private:
    const ProfileAttribute* attribute_;
    const IProfileAttribute* attribute_;
    std::string value_;
    std::string value_;
};
};


@@ -180,7 +190,7 @@ class TaskProfiles {
    static TaskProfiles& GetInstance();
    static TaskProfiles& GetInstance();


    TaskProfile* GetProfile(const std::string& name) const;
    TaskProfile* GetProfile(const std::string& name) const;
    const ProfileAttribute* GetAttribute(const std::string& name) const;
    const IProfileAttribute* GetAttribute(const std::string& name) const;
    void DropResourceCaching(ProfileAction::ResourceCacheType cache_type) const;
    void DropResourceCaching(ProfileAction::ResourceCacheType cache_type) const;
    bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles,
    bool SetProcessProfiles(uid_t uid, pid_t pid, const std::vector<std::string>& profiles,
                            bool use_fd_cache);
                            bool use_fd_cache);
@@ -188,7 +198,7 @@ class TaskProfiles {


  private:
  private:
    std::map<std::string, std::shared_ptr<TaskProfile>> profiles_;
    std::map<std::string, std::shared_ptr<TaskProfile>> profiles_;
    std::map<std::string, std::unique_ptr<ProfileAttribute>> attributes_;
    std::map<std::string, std::unique_ptr<IProfileAttribute>> attributes_;


    TaskProfiles();
    TaskProfiles();