Loading libprocessgroup/task_profiles.cpp +12 −22 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,6 @@ #include <task_profiles.h> #include <task_profiles.h> #include <map> #include <map> #include <optional> #include <string> #include <string> #include <dirent.h> #include <dirent.h> Loading @@ -31,6 +30,7 @@ #include <android-base/file.h> #include <android-base/file.h> #include <android-base/logging.h> #include <android-base/logging.h> #include <android-base/parseint.h> #include <android-base/properties.h> #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <android-base/strings.h> Loading Loading @@ -121,15 +121,6 @@ bool FdCacheHelper::IsAppDependentPath(const std::string& path) { return path.find("<uid>", 0) != std::string::npos || path.find("<pid>", 0) != std::string::npos; return path.find("<uid>", 0) != std::string::npos || path.find("<pid>", 0) != std::string::npos; } } std::optional<long> readLong(const std::string& str) { char* end; const long result = strtol(str.c_str(), &end, 10); if (end > str.c_str()) { return result; } return std::nullopt; } } // namespace } // namespace IProfileAttribute::~IProfileAttribute() = default; IProfileAttribute::~IProfileAttribute() = default; Loading Loading @@ -930,9 +921,8 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) { } } } else if (action_name == "SetTimerSlack") { } else if (action_name == "SetTimerSlack") { const std::string slack_string = params_val["Slack"].asString(); const std::string slack_string = params_val["Slack"].asString(); std::optional<long> slack = readLong(slack_string); if (long slack; android::base::ParseInt(slack_string, &slack) && slack >= 0) { if (slack && *slack >= 0) { profile->Add(std::make_unique<SetTimerSlackAction>(slack)); profile->Add(std::make_unique<SetTimerSlackAction>(*slack)); } else { } else { LOG(WARNING) << "SetTimerSlack: invalid parameter: " << slack_string; LOG(WARNING) << "SetTimerSlack: invalid parameter: " << slack_string; } } Loading Loading @@ -994,18 +984,17 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) { // to setpriority(), since the sched_priority value must be 0 for calls to // to setpriority(), since the sched_priority value must be 0 for calls to // sched_setscheduler() with "normal" policies. // sched_setscheduler() with "normal" policies. const std::string nice_string = params_val["Nice"].asString(); const std::string nice_string = params_val["Nice"].asString(); const std::optional<int> nice = readLong(nice_string); int nice; if (!android::base::ParseInt(nice_string, &nice)) { if (!nice) { LOG(FATAL) << "Invalid nice value specified: " << nice_string; LOG(FATAL) << "Invalid nice value specified: " << nice_string; } } const int LINUX_MIN_NICE = -20; const int LINUX_MIN_NICE = -20; const int LINUX_MAX_NICE = 19; const int LINUX_MAX_NICE = 19; if (*nice < LINUX_MIN_NICE || *nice > LINUX_MAX_NICE) { if (nice < LINUX_MIN_NICE || nice > LINUX_MAX_NICE) { LOG(WARNING) << "SetSchedulerPolicy: Provided nice (" << *nice LOG(WARNING) << "SetSchedulerPolicy: Provided nice (" << nice << ") appears out of range."; << ") appears out of range."; } } profile->Add(std::make_unique<SetSchedulerPolicyAction>(policy, *nice)); profile->Add(std::make_unique<SetSchedulerPolicyAction>(policy, nice)); } else { } else { profile->Add(std::make_unique<SetSchedulerPolicyAction>(policy)); profile->Add(std::make_unique<SetSchedulerPolicyAction>(policy)); } } Loading @@ -1020,10 +1009,11 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) { // [sched_get_priority_min(), sched_get_priority_max()] // [sched_get_priority_min(), sched_get_priority_max()] const std::string priority_string = params_val["Priority"].asString(); const std::string priority_string = params_val["Priority"].asString(); std::optional<long> virtual_priority = readLong(priority_string); if (long virtual_priority; if (virtual_priority && *virtual_priority > 0) { android::base::ParseInt(priority_string, &virtual_priority) && virtual_priority > 0) { int priority; int priority; if (SetSchedulerPolicyAction::toPriority(policy, *virtual_priority, if (SetSchedulerPolicyAction::toPriority(policy, virtual_priority, priority)) { priority)) { profile->Add( profile->Add( std::make_unique<SetSchedulerPolicyAction>(policy, priority)); std::make_unique<SetSchedulerPolicyAction>(policy, priority)); Loading Loading
libprocessgroup/task_profiles.cpp +12 −22 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,6 @@ #include <task_profiles.h> #include <task_profiles.h> #include <map> #include <map> #include <optional> #include <string> #include <string> #include <dirent.h> #include <dirent.h> Loading @@ -31,6 +30,7 @@ #include <android-base/file.h> #include <android-base/file.h> #include <android-base/logging.h> #include <android-base/logging.h> #include <android-base/parseint.h> #include <android-base/properties.h> #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <android-base/stringprintf.h> #include <android-base/strings.h> #include <android-base/strings.h> Loading Loading @@ -121,15 +121,6 @@ bool FdCacheHelper::IsAppDependentPath(const std::string& path) { return path.find("<uid>", 0) != std::string::npos || path.find("<pid>", 0) != std::string::npos; return path.find("<uid>", 0) != std::string::npos || path.find("<pid>", 0) != std::string::npos; } } std::optional<long> readLong(const std::string& str) { char* end; const long result = strtol(str.c_str(), &end, 10); if (end > str.c_str()) { return result; } return std::nullopt; } } // namespace } // namespace IProfileAttribute::~IProfileAttribute() = default; IProfileAttribute::~IProfileAttribute() = default; Loading Loading @@ -930,9 +921,8 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) { } } } else if (action_name == "SetTimerSlack") { } else if (action_name == "SetTimerSlack") { const std::string slack_string = params_val["Slack"].asString(); const std::string slack_string = params_val["Slack"].asString(); std::optional<long> slack = readLong(slack_string); if (long slack; android::base::ParseInt(slack_string, &slack) && slack >= 0) { if (slack && *slack >= 0) { profile->Add(std::make_unique<SetTimerSlackAction>(slack)); profile->Add(std::make_unique<SetTimerSlackAction>(*slack)); } else { } else { LOG(WARNING) << "SetTimerSlack: invalid parameter: " << slack_string; LOG(WARNING) << "SetTimerSlack: invalid parameter: " << slack_string; } } Loading Loading @@ -994,18 +984,17 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) { // to setpriority(), since the sched_priority value must be 0 for calls to // to setpriority(), since the sched_priority value must be 0 for calls to // sched_setscheduler() with "normal" policies. // sched_setscheduler() with "normal" policies. const std::string nice_string = params_val["Nice"].asString(); const std::string nice_string = params_val["Nice"].asString(); const std::optional<int> nice = readLong(nice_string); int nice; if (!android::base::ParseInt(nice_string, &nice)) { if (!nice) { LOG(FATAL) << "Invalid nice value specified: " << nice_string; LOG(FATAL) << "Invalid nice value specified: " << nice_string; } } const int LINUX_MIN_NICE = -20; const int LINUX_MIN_NICE = -20; const int LINUX_MAX_NICE = 19; const int LINUX_MAX_NICE = 19; if (*nice < LINUX_MIN_NICE || *nice > LINUX_MAX_NICE) { if (nice < LINUX_MIN_NICE || nice > LINUX_MAX_NICE) { LOG(WARNING) << "SetSchedulerPolicy: Provided nice (" << *nice LOG(WARNING) << "SetSchedulerPolicy: Provided nice (" << nice << ") appears out of range."; << ") appears out of range."; } } profile->Add(std::make_unique<SetSchedulerPolicyAction>(policy, *nice)); profile->Add(std::make_unique<SetSchedulerPolicyAction>(policy, nice)); } else { } else { profile->Add(std::make_unique<SetSchedulerPolicyAction>(policy)); profile->Add(std::make_unique<SetSchedulerPolicyAction>(policy)); } } Loading @@ -1020,10 +1009,11 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) { // [sched_get_priority_min(), sched_get_priority_max()] // [sched_get_priority_min(), sched_get_priority_max()] const std::string priority_string = params_val["Priority"].asString(); const std::string priority_string = params_val["Priority"].asString(); std::optional<long> virtual_priority = readLong(priority_string); if (long virtual_priority; if (virtual_priority && *virtual_priority > 0) { android::base::ParseInt(priority_string, &virtual_priority) && virtual_priority > 0) { int priority; int priority; if (SetSchedulerPolicyAction::toPriority(policy, *virtual_priority, if (SetSchedulerPolicyAction::toPriority(policy, virtual_priority, priority)) { priority)) { profile->Add( profile->Add( std::make_unique<SetSchedulerPolicyAction>(policy, priority)); std::make_unique<SetSchedulerPolicyAction>(policy, priority)); Loading