Merge "libprocessgroup: Prevent aggregate profiles from referencing stale ones"

am: 5562b076b7

Change-Id: I96db8c4038d17bb200946204a0548236ffb76c1a
This commit is contained in:
Suren Baghdasaryan 2020-01-27 16:54:08 -08:00 committed by android-build-merger
commit e7a707cfbd
2 changed files with 15 additions and 1 deletions

View file

@ -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"];

View file

@ -143,6 +143,7 @@ class TaskProfile {
TaskProfile() : res_cached_(false) {}
void Add(std::unique_ptr<ProfileAction> 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;