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

Commit 2ffbeaef authored by Suren Baghdasaryan's avatar Suren Baghdasaryan
Browse files

libprocessgroup: fix reset of file_v2_name



ProfileAttribute::Reset does not reset file_v2_name, fix that. Also
provide ProfileAttribute::file_name() to consolidate the code.

Bug: 292636609
Signed-off-by: default avatarSuren Baghdasaryan <surenb@google.com>
Change-Id: I5b33ca47b4fa5cabf582c8804bd13f72f6e58411
Merged-In: I5b33ca47b4fa5cabf582c8804bd13f72f6e58411
parent e8e0389f
Loading
Loading
Loading
Loading
+13 −9
Original line number Original line Diff line number Diff line
@@ -114,9 +114,16 @@ bool FdCacheHelper::IsAppDependentPath(const std::string& path) {


IProfileAttribute::~IProfileAttribute() = default;
IProfileAttribute::~IProfileAttribute() = default;


void ProfileAttribute::Reset(const CgroupController& controller, const std::string& file_name) {
const std::string& ProfileAttribute::file_name() const {
    if (controller()->version() == 2 && !file_v2_name_.empty()) return file_v2_name_;
    return file_name_;
}

void ProfileAttribute::Reset(const CgroupController& controller, const std::string& file_name,
                             const std::string& file_v2_name) {
    controller_ = controller;
    controller_ = controller;
    file_name_ = file_name;
    file_name_ = file_name;
    file_v2_name_ = file_v2_name;
}
}


bool ProfileAttribute::GetPathForTask(int tid, std::string* path) const {
bool ProfileAttribute::GetPathForTask(int tid, std::string* path) const {
@@ -129,12 +136,11 @@ bool ProfileAttribute::GetPathForTask(int tid, std::string* path) const {
        return true;
        return true;
    }
    }


    const std::string& file_name =
            controller()->version() == 2 && !file_v2_name_.empty() ? file_v2_name_ : file_name_;
    if (subgroup.empty()) {
    if (subgroup.empty()) {
        *path = StringPrintf("%s/%s", controller()->path(), file_name.c_str());
        *path = StringPrintf("%s/%s", controller()->path(), file_name().c_str());
    } else {
    } else {
        *path = StringPrintf("%s/%s/%s", controller()->path(), subgroup.c_str(), file_name.c_str());
        *path = StringPrintf("%s/%s/%s", controller()->path(), subgroup.c_str(),
                             file_name().c_str());
    }
    }
    return true;
    return true;
}
}
@@ -144,9 +150,7 @@ bool ProfileAttribute::GetPathForUID(uid_t uid, std::string* path) const {
        return true;
        return true;
    }
    }


    const std::string& file_name =
    *path = StringPrintf("%s/uid_%u/%s", controller()->path(), uid, file_name().c_str());
            controller()->version() == 2 && !file_v2_name_.empty() ? file_v2_name_ : file_name_;
    *path = StringPrintf("%s/uid_%d/%s", controller()->path(), uid, file_name.c_str());
    return true;
    return true;
}
}


@@ -816,7 +820,7 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) {
                attributes_[name] =
                attributes_[name] =
                        std::make_unique<ProfileAttribute>(controller, file_attr, file_v2_attr);
                        std::make_unique<ProfileAttribute>(controller, file_attr, file_v2_attr);
            } else {
            } else {
                iter->second->Reset(controller, file_attr);
                iter->second->Reset(controller, file_attr, file_v2_attr);
            }
            }
        } else {
        } else {
            LOG(WARNING) << "Controller " << controller_name << " is not found";
            LOG(WARNING) << "Controller " << controller_name << " is not found";
+5 −3
Original line number Original line Diff line number Diff line
@@ -32,7 +32,8 @@
class IProfileAttribute {
class IProfileAttribute {
  public:
  public:
    virtual ~IProfileAttribute() = 0;
    virtual ~IProfileAttribute() = 0;
    virtual void Reset(const CgroupController& controller, const std::string& file_name) = 0;
    virtual void Reset(const CgroupController& controller, const std::string& file_name,
                       const std::string& file_v2_name) = 0;
    virtual const CgroupController* controller() const = 0;
    virtual const CgroupController* controller() const = 0;
    virtual const std::string& file_name() const = 0;
    virtual const std::string& file_name() const = 0;
    virtual bool GetPathForTask(int tid, std::string* path) const = 0;
    virtual bool GetPathForTask(int tid, std::string* path) const = 0;
@@ -50,8 +51,9 @@ class ProfileAttribute : public IProfileAttribute {
    ~ProfileAttribute() = default;
    ~ProfileAttribute() = default;


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


    bool GetPathForTask(int tid, std::string* path) const override;
    bool GetPathForTask(int tid, std::string* path) const override;
    bool GetPathForUID(uid_t uid, std::string* path) const override;
    bool GetPathForUID(uid_t uid, std::string* path) const override;
+3 −4
Original line number Original line Diff line number Diff line
@@ -102,7 +102,8 @@ class ProfileAttributeMock : public IProfileAttribute {
  public:
  public:
    ProfileAttributeMock(const std::string& file_name) : file_name_(file_name) {}
    ProfileAttributeMock(const std::string& file_name) : file_name_(file_name) {}
    ~ProfileAttributeMock() override = default;
    ~ProfileAttributeMock() override = default;
    void Reset(const CgroupController& controller, const std::string& file_name) override {
    void Reset(const CgroupController& controller, const std::string& file_name,
               const std::string& file_v2_name) override {
        CHECK(false);
        CHECK(false);
    }
    }
    const CgroupController* controller() const override {
    const CgroupController* controller() const override {
@@ -125,9 +126,7 @@ class ProfileAttributeMock : public IProfileAttribute {
        return true;
        return true;
    };
    };


    bool GetPathForUID(uid_t, std::string*) const override {
    bool GetPathForUID(uid_t, std::string*) const override { return false; }
        return false;
    }


  private:
  private:
    const std::string file_name_;
    const std::string file_name_;