Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9252d313 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "init: add error handling in control message"

parents b42af0eb 5f01d3af
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -280,13 +280,13 @@ static const std::map<std::string, ControlMessageFunction>& get_control_message_
    return control_message_functions;
    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& map = get_control_message_map();
    const auto it = map.find(msg);
    const auto it = map.find(msg);


    if (it == map.end()) {
    if (it == map.end()) {
        LOG(ERROR) << "Unknown control msg '" << msg << "'";
        LOG(ERROR) << "Unknown control msg '" << msg << "'";
        return;
        return false;
    }
    }


    std::string cmdline_path = StringPrintf("proc/%d/cmdline", pid);
    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:
        default:
            LOG(ERROR) << "Invalid function target from static map key '" << msg << "': "
            LOG(ERROR) << "Invalid function target from static map key '" << msg << "': "
                       << static_cast<std::underlying_type<ControlTarget>::type>(function.target);
                       << static_cast<std::underlying_type<ControlTarget>::type>(function.target);
            return;
            return false;
    }
    }


    if (svc == nullptr) {
    if (svc == nullptr) {
        LOG(ERROR) << "Could not find '" << name << "' for ctl." << msg;
        LOG(ERROR) << "Could not find '" << name << "' for ctl." << msg;
        return;
        return false;
    }
    }


    if (auto result = function.action(svc); !result) {
    if (auto result = function.action(svc); !result) {
        LOG(ERROR) << "Could not ctl." << msg << " for '" << name << "': " << result.error();
        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) {
static Result<Success> wait_for_coldboot_done_action(const BuiltinArguments& args) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -40,7 +40,7 @@ extern std::vector<std::string> late_import_paths;
Parser CreateParser(ActionManager& action_manager, ServiceList& service_list);
Parser CreateParser(ActionManager& action_manager, ServiceList& service_list);
Parser CreateServiceOnlyParser(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);
void property_changed(const std::string& name, const std::string& value);


+3 −2
Original line number Original line Diff line number Diff line
@@ -473,8 +473,9 @@ uint32_t HandlePropertySet(const std::string& name, const std::string& value,
    }
    }


    if (StartsWith(name, "ctl.")) {
    if (StartsWith(name, "ctl.")) {
        HandleControlMessage(name.c_str() + 4, value, cr.pid);
        return HandleControlMessage(name.c_str() + 4, value, cr.pid)
        return PROP_SUCCESS;
                       ? 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
    // sys.powerctl is a special property that is used to make the device reboot.  We want to log