init: add error handling in control message

Bug: 133432022
Test: boot
Test: setprop ctl.interface_restart android.hardware.power@1.0::IPower/default success
Test: setprop ctl.interface_restart android.hardware.power@1.0::IPower/abc fail
Change-Id: I66342b2723eb01022fb4e0d98f0b6ffc2752bcac
This commit is contained in:
Wei Wang 2019-05-23 12:13:29 -07:00
parent cbe0876f8b
commit 5f01d3af77
3 changed files with 10 additions and 7 deletions

View file

@ -280,13 +280,13 @@ static const std::map<std::string, ControlMessageFunction>& get_control_message_
return control_message_functions;
}
void HandleControlMessage(const std::string& msg, const std::string& name, pid_t pid) {
bool HandleControlMessage(const std::string& msg, const std::string& name, pid_t pid) {
const auto& map = get_control_message_map();
const auto it = map.find(msg);
if (it == map.end()) {
LOG(ERROR) << "Unknown control msg '" << msg << "'";
return;
return false;
}
std::string cmdline_path = StringPrintf("proc/%d/cmdline", pid);
@ -315,17 +315,19 @@ void HandleControlMessage(const std::string& msg, const std::string& name, pid_t
default:
LOG(ERROR) << "Invalid function target from static map key '" << msg << "': "
<< static_cast<std::underlying_type<ControlTarget>::type>(function.target);
return;
return false;
}
if (svc == nullptr) {
LOG(ERROR) << "Could not find '" << name << "' for ctl." << msg;
return;
return false;
}
if (auto result = function.action(svc); !result) {
LOG(ERROR) << "Could not ctl." << msg << " for '" << name << "': " << result.error();
return false;
}
return true;
}
static Result<Success> wait_for_coldboot_done_action(const BuiltinArguments& args) {

View file

@ -40,7 +40,7 @@ extern std::vector<std::string> late_import_paths;
Parser CreateParser(ActionManager& action_manager, ServiceList& service_list);
Parser CreateServiceOnlyParser(ServiceList& service_list);
void HandleControlMessage(const std::string& msg, const std::string& arg, pid_t pid);
bool HandleControlMessage(const std::string& msg, const std::string& arg, pid_t pid);
void property_changed(const std::string& name, const std::string& value);

View file

@ -473,8 +473,9 @@ uint32_t HandlePropertySet(const std::string& name, const std::string& value,
}
if (StartsWith(name, "ctl.")) {
HandleControlMessage(name.c_str() + 4, value, cr.pid);
return PROP_SUCCESS;
return HandleControlMessage(name.c_str() + 4, value, cr.pid)
? PROP_SUCCESS
: PROP_ERROR_HANDLE_CONTROL_MESSAGE;
}
// sys.powerctl is a special property that is used to make the device reboot. We want to log