Return Result<T> from Do(Un)LoadApex()

For consistent error message. This is a preparation step for the
follow-up change: to generate linker configuration in DoLoadApex()

Bug: 232173613
Test: CtsInitTestCases
Change-Id: I27954ae2429e82da1bde1925ef62b277c24129d3
diff --git a/init/init.cpp b/init/init.cpp
index 0658942..e40627f 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -442,17 +442,19 @@
     return {};
 }
 
-static void DoUnloadApex(const std::string& apex_name) {
+static Result<void> DoUnloadApex(const std::string& apex_name) {
     std::string prop_name = "init.apex." + apex_name;
     // TODO(b/232114573) remove services and actions read from the apex
     // TODO(b/232799709) kill services from the apex
     SetProperty(prop_name, "unloaded");
+    return {};
 }
 
-static void DoLoadApex(const std::string& apex_name) {
+static Result<void> DoLoadApex(const std::string& apex_name) {
     std::string prop_name = "init.apex." + apex_name;
     // TODO(b/232799709) read .rc files from the apex
     SetProperty(prop_name, "loaded");
+    return {};
 }
 
 enum class ControlTarget {
@@ -478,17 +480,14 @@
     return control_message_functions;
 }
 
-static bool HandleApexControlMessage(std::string_view action, const std::string& name,
-                                     std::string_view message) {
+static Result<void> HandleApexControlMessage(std::string_view action, const std::string& name,
+                                             std::string_view message) {
     if (action == "load") {
-        DoLoadApex(name);
-        return true;
+        return DoLoadApex(name);
     } else if (action == "unload") {
-        DoUnloadApex(name);
-        return true;
+        return DoUnloadApex(name);
     } else {
-        LOG(ERROR) << "Unknown control msg '" << message << "'";
-        return false;
+        return Error() << "Unknown control msg '" << message << "'";
     }
 }
 
@@ -505,7 +504,15 @@
 
     auto action = message;
     if (ConsumePrefix(&action, "apex_")) {
-        return HandleApexControlMessage(action, name, message);
+        if (auto result = HandleApexControlMessage(action, name, message); !result.ok()) {
+            LOG(ERROR) << "Control message: Could not ctl." << message << " for '" << name
+                       << "' from pid: " << from_pid << " (" << process_cmdline
+                       << "): " << result.error();
+            return false;
+        }
+        LOG(INFO) << "Control message: Processed ctl." << message << " for '" << name
+                  << "' from pid: " << from_pid << " (" << process_cmdline << ")";
+        return true;
     }
 
     Service* service = nullptr;