libprocessgroup: Support write to file feature
There may be some use cases that it needs to write string to a
file. This patch support write "Value" to "FilePath", where
both parameters could use special string "<uid>" and "<pid>" to
represent actual uid and pid.
Bug: 170507963
Test: function works
Change-Id: I543846f523518a9bcb3dd1b3437163a1b3157d95
diff --git a/libprocessgroup/task_profiles.h b/libprocessgroup/task_profiles.h
index 2983a09..98bcb0e 100644
--- a/libprocessgroup/task_profiles.h
+++ b/libprocessgroup/task_profiles.h
@@ -139,6 +139,19 @@
bool IsFdValid() const { return fd_ > FDS_INACCESSIBLE; }
};
+// Write to file action
+class WriteFileAction : public ProfileAction {
+ public:
+ WriteFileAction(const std::string& filepath, const std::string& value) noexcept
+ : filepath_(filepath), value_(value) {}
+
+ virtual bool ExecuteForProcess(uid_t uid, pid_t pid) const;
+ virtual bool ExecuteForTask(int tid) const;
+
+ private:
+ std::string filepath_, value_;
+};
+
class TaskProfile {
public:
TaskProfile() : res_cached_(false) {}