From 5f01d3af77d420c0bd0688e86ceb9c7772c1c76a Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Thu, 23 May 2019 12:13:29 -0700 Subject: [PATCH] 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 --- init/init.cpp | 10 ++++++---- init/init.h | 2 +- init/property_service.cpp | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/init/init.cpp b/init/init.cpp index 1f3c2fc25..0615d4479 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -280,13 +280,13 @@ static const std::map& 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::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 wait_for_coldboot_done_action(const BuiltinArguments& args) { diff --git a/init/init.h b/init/init.h index a76da2014..90ead0edb 100644 --- a/init/init.h +++ b/init/init.h @@ -40,7 +40,7 @@ extern std::vector 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); diff --git a/init/property_service.cpp b/init/property_service.cpp index 14e83f2b7..ab5dd6146 100644 --- a/init/property_service.cpp +++ b/init/property_service.cpp @@ -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