Support process path for WriteFileAction
Currently, there is no distinguish between SetTaskProfiles and
SetProcessProfiles in WriteFileAction because they use the same task
path. Add ProcFilePath attribute so that WriteFileAction could use
a separate path for process in SetProcessProfiles.
Bug: 218684257
Test: function works
Change-Id: I004b8c8799240c54f1ef1fed0566fa5057341cf4
diff --git a/libprocessgroup/task_profiles.h b/libprocessgroup/task_profiles.h
index 2f48664..ecc67a3 100644
--- a/libprocessgroup/task_profiles.h
+++ b/libprocessgroup/task_profiles.h
@@ -134,7 +134,8 @@
// Write to file action
class WriteFileAction : public ProfileAction {
public:
- WriteFileAction(const std::string& path, const std::string& value, bool logfailures);
+ WriteFileAction(const std::string& task_path, const std::string& proc_path,
+ const std::string& value, bool logfailures);
bool ExecuteForProcess(uid_t uid, pid_t pid) const override;
bool ExecuteForTask(int tid) const override;
@@ -142,13 +143,13 @@
void DropResourceCaching(ResourceCacheType cache_type) override;
private:
- std::string path_, value_;
+ std::string task_path_, proc_path_, value_;
bool logfailures_;
- android::base::unique_fd fd_;
+ android::base::unique_fd fd_[ProfileAction::RCT_COUNT];
mutable std::mutex fd_mutex_;
- static bool WriteValueToFile(const std::string& value, const std::string& path,
- bool logfailures);
+ bool WriteValueToFile(const std::string& value, ResourceCacheType cache_type, int uid, int pid,
+ bool logfailures) const;
CacheUseResult UseCachedFd(ResourceCacheType cache_type, const std::string& value) const;
};