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

Commit a550e7f4 authored by Tom Cherry's avatar Tom Cherry Committed by Gerrit Code Review
Browse files

Merge "init: add reboot_on_failure service option"

parents 10158812 60971e6c
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -263,6 +263,12 @@ runs the service.
> Scheduling priority of the service process. This value has to be in range
> Scheduling priority of the service process. This value has to be in range
  -20 to 19. Default priority is 0. Priority is set via setpriority().
  -20 to 19. Default priority is 0. Priority is set via setpriority().


`reboot_on_failure <target>`
> If this process cannot be started or if the process terminates with an exit code other than
  CLD_EXITED or an status other than '0', reboot the system with the target specified in
  _target_. _target_ takes the same format as the parameter to sys.powerctl. This is particularly
  intended to be used with the `exec_start` builtin for any must-have checks during boot.

`restart_period <seconds>`
`restart_period <seconds>`
> If a non-oneshot service exits, it will be restarted at its start time plus
> If a non-oneshot service exits, it will be restarted at its start time plus
  this period. It defaults to 5s to rate limit crashing services.
  this period. It defaults to 5s to rate limit crashing services.
+0 −15
Original line number Original line Diff line number Diff line
@@ -1104,20 +1104,6 @@ static Result<void> ExecWithFunctionOnFailure(const std::vector<std::string>& ar
    return {};
    return {};
}
}


static Result<void> do_exec_reboot_on_failure(const BuiltinArguments& args) {
    auto reboot_reason = args[1];
    auto reboot = [reboot_reason](const std::string& message) {
        property_set(LAST_REBOOT_REASON_PROPERTY, reboot_reason);
        sync();
        LOG(FATAL) << message << ": rebooting into bootloader, reason: " << reboot_reason;
    };

    std::vector<std::string> remaining_args(args.begin() + 1, args.end());
    remaining_args[0] = args[0];

    return ExecWithFunctionOnFailure(remaining_args, reboot);
}

static Result<void> ExecVdcRebootOnFailure(const std::string& vdc_arg) {
static Result<void> ExecVdcRebootOnFailure(const std::string& vdc_arg) {
    auto reboot_reason = vdc_arg + "_failed";
    auto reboot_reason = vdc_arg + "_failed";


@@ -1225,7 +1211,6 @@ const BuiltinFunctionMap& GetBuiltinFunctionMap() {
        {"enable",                  {1,     1,    {false,  do_enable}}},
        {"enable",                  {1,     1,    {false,  do_enable}}},
        {"exec",                    {1,     kMax, {false,  do_exec}}},
        {"exec",                    {1,     kMax, {false,  do_exec}}},
        {"exec_background",         {1,     kMax, {false,  do_exec_background}}},
        {"exec_background",         {1,     kMax, {false,  do_exec_background}}},
        {"exec_reboot_on_failure",  {2,     kMax, {false,  do_exec_reboot_on_failure}}},
        {"exec_start",              {1,     1,    {false,  do_exec_start}}},
        {"exec_start",              {1,     1,    {false,  do_exec_start}}},
        {"export",                  {2,     2,    {false,  do_export}}},
        {"export",                  {2,     2,    {false,  do_export}}},
        {"hostname",                {1,     1,    {true,   do_hostname}}},
        {"hostname",                {1,     1,    {true,   do_hostname}}},
+5 −0
Original line number Original line Diff line number Diff line
@@ -34,6 +34,11 @@
namespace android {
namespace android {
namespace init {
namespace init {


// init.h
inline void EnterShutdown(const std::string&) {
    abort();
}

// property_service.h
// property_service.h
inline bool CanReadProperty(const std::string&, const std::string&) {
inline bool CanReadProperty(const std::string&, const std::string&) {
    return true;
    return true;
+11 −10
Original line number Original line Diff line number Diff line
@@ -180,6 +180,16 @@ void ResetWaitForProp() {
    waiting_for_prop.reset();
    waiting_for_prop.reset();
}
}


void EnterShutdown(const std::string& command) {
    // We can't call HandlePowerctlMessage() directly in this function,
    // because it modifies the contents of the action queue, which can cause the action queue
    // to get into a bad state if this function is called from a command being executed by the
    // action queue.  Instead we set this flag and ensure that shutdown happens before the next
    // command is run in the main init loop.
    shutdown_command = command;
    do_shutdown = true;
}

void property_changed(const std::string& name, const std::string& value) {
void property_changed(const std::string& name, const std::string& value) {
    // If the property is sys.powerctl, we bypass the event queue and immediately handle it.
    // If the property is sys.powerctl, we bypass the event queue and immediately handle it.
    // This is to ensure that init will always and immediately shutdown/reboot, regardless of
    // This is to ensure that init will always and immediately shutdown/reboot, regardless of
@@ -188,16 +198,7 @@ void property_changed(const std::string& name, const std::string& value) {
    // In non-thermal-shutdown case, 'shutdown' trigger will be fired to let device specific
    // In non-thermal-shutdown case, 'shutdown' trigger will be fired to let device specific
    // commands to be executed.
    // commands to be executed.
    if (name == "sys.powerctl") {
    if (name == "sys.powerctl") {
        // Despite the above comment, we can't call HandlePowerctlMessage() in this function,
        EnterShutdown(value);
        // because it modifies the contents of the action queue, which can cause the action queue
        // to get into a bad state if this function is called from a command being executed by the
        // action queue.  Instead we set this flag and ensure that shutdown happens before the next
        // command is run in the main init loop.
        // TODO: once property service is removed from init, this will never happen from a builtin,
        // but rather from a callback from the property service socket, in which case this hack can
        // go away.
        shutdown_command = value;
        do_shutdown = true;
    }
    }


    if (property_triggers_enabled) ActionManager::GetInstance().QueuePropertyChange(name, value);
    if (property_triggers_enabled) ActionManager::GetInstance().QueuePropertyChange(name, value);
+2 −0
Original line number Original line Diff line number Diff line
@@ -31,6 +31,8 @@ namespace init {
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 EnterShutdown(const std::string& command);

bool start_waiting_for_property(const char *name, const char *value);
bool start_waiting_for_property(const char *name, const char *value);


void DumpState();
void DumpState();
Loading