diff options
Diffstat (limited to 'libprocessgroup/task_profiles.h')
-rw-r--r-- | libprocessgroup/task_profiles.h | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/libprocessgroup/task_profiles.h b/libprocessgroup/task_profiles.h index 25a84b0c1..278892dd5 100644 --- a/libprocessgroup/task_profiles.h +++ b/libprocessgroup/task_profiles.h @@ -108,50 +108,67 @@ class SetAttributeAction : public ProfileAction { std::string value_; }; -// Set cgroup profile element -class SetCgroupAction : public ProfileAction { +// Abstract profile element for cached fd +class CachedFdProfileAction : public ProfileAction { public: - SetCgroupAction(const CgroupController& c, const std::string& p); - - virtual bool ExecuteForProcess(uid_t uid, pid_t pid) const; - virtual bool ExecuteForTask(int tid) const; virtual void EnableResourceCaching(); virtual void DropResourceCaching(); - const CgroupController* controller() const { return &controller_; } - std::string path() const { return path_; } - - private: + protected: enum FdState { FDS_INACCESSIBLE = -1, FDS_APP_DEPENDENT = -2, FDS_NOT_CACHED = -3, }; - CgroupController controller_; - std::string path_; android::base::unique_fd fd_; mutable std::mutex fd_mutex_; static bool IsAppDependentPath(const std::string& path); - static bool AddTidToCgroup(int tid, int fd); + void InitFd(const std::string& path); bool IsFdValid() const { return fd_ > FDS_INACCESSIBLE; } + + virtual const std::string GetPath() const = 0; +}; + +// Set cgroup profile element +class SetCgroupAction : public CachedFdProfileAction { + public: + SetCgroupAction(const CgroupController& c, const std::string& p); + + virtual bool ExecuteForProcess(uid_t uid, pid_t pid) const; + virtual bool ExecuteForTask(int tid) const; + + const CgroupController* controller() const { return &controller_; } + + protected: + const std::string GetPath() const override { return controller_.GetTasksFilePath(path_); } + + private: + CgroupController controller_; + std::string path_; + + static bool AddTidToCgroup(int tid, int fd, const char* controller_name); }; // Write to file action -class WriteFileAction : public ProfileAction { +class WriteFileAction : public CachedFdProfileAction { public: - WriteFileAction(const std::string& filepath, const std::string& value, - bool logfailures) noexcept - : filepath_(filepath), value_(value), logfailures_(logfailures) {} + WriteFileAction(const std::string& path, const std::string& value, bool logfailures); virtual bool ExecuteForProcess(uid_t uid, pid_t pid) const; virtual bool ExecuteForTask(int tid) const; + protected: + const std::string GetPath() const override { return path_; } + private: - std::string filepath_, value_; + std::string path_, value_; bool logfailures_; + + static bool WriteValueToFile(const std::string& value, const std::string& path, + bool logfailures); }; class TaskProfile { |