diff --git a/libprocessgroup/task_profiles.cpp b/libprocessgroup/task_profiles.cpp index 9447f864b..72f01af67 100644 --- a/libprocessgroup/task_profiles.cpp +++ b/libprocessgroup/task_profiles.cpp @@ -288,6 +288,11 @@ bool ApplyProfileAction::ExecuteForTask(int tid) const { return true; } +void TaskProfile::MoveTo(TaskProfile* profile) { + profile->elements_ = std::move(elements_); + profile->res_cached_ = res_cached_; +} + bool TaskProfile::ExecuteForProcess(uid_t uid, pid_t pid) const { for (const auto& element : elements_) { if (!element->ExecuteForProcess(uid, pid)) { @@ -458,7 +463,15 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) { LOG(WARNING) << "Unknown profile action: " << action_name; } } - profiles_[profile_name] = profile; + auto iter = profiles_.find(profile_name); + if (iter == profiles_.end()) { + profiles_[profile_name] = profile; + } else { + // Move the content rather that replace the profile because old profile might be + // referenced from an aggregate profile if vendor overrides task profiles + profile->MoveTo(iter->second.get()); + profile.reset(); + } } const Json::Value& aggregateprofiles_val = root["AggregateProfiles"]; diff --git a/libprocessgroup/task_profiles.h b/libprocessgroup/task_profiles.h index 9f2308c64..a64ca50ad 100644 --- a/libprocessgroup/task_profiles.h +++ b/libprocessgroup/task_profiles.h @@ -143,6 +143,7 @@ class TaskProfile { TaskProfile() : res_cached_(false) {} void Add(std::unique_ptr e) { elements_.push_back(std::move(e)); } + void MoveTo(TaskProfile* profile); bool ExecuteForProcess(uid_t uid, pid_t pid) const; bool ExecuteForTask(int tid) const;