Loading init/README.md +6 −0 Original line number Diff line number Diff line Loading @@ -263,6 +263,12 @@ runs the service. > 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(). `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>` > 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. Loading init/builtins.cpp +0 −15 Original line number Diff line number Diff line Loading @@ -1104,20 +1104,6 @@ static Result<void> ExecWithFunctionOnFailure(const std::vector<std::string>& ar 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) { auto reboot_reason = vdc_arg + "_failed"; Loading Loading @@ -1225,7 +1211,6 @@ const BuiltinFunctionMap& GetBuiltinFunctionMap() { {"enable", {1, 1, {false, do_enable}}}, {"exec", {1, kMax, {false, do_exec}}}, {"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}}}, {"export", {2, 2, {false, do_export}}}, {"hostname", {1, 1, {true, do_hostname}}}, Loading init/host_init_stubs.h +5 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,11 @@ namespace android { namespace init { // init.h inline void EnterShutdown(const std::string&) { abort(); } // property_service.h inline bool CanReadProperty(const std::string&, const std::string&) { return true; Loading init/init.cpp +11 −10 Original line number Diff line number Diff line Loading @@ -180,6 +180,16 @@ void ResetWaitForProp() { 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) { // 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 Loading @@ -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 // commands to be executed. if (name == "sys.powerctl") { // Despite the above comment, we can't call HandlePowerctlMessage() 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. // 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; EnterShutdown(value); } if (property_triggers_enabled) ActionManager::GetInstance().QueuePropertyChange(name, value); Loading init/init.h +2 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ namespace init { Parser CreateParser(ActionManager& action_manager, 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); void DumpState(); Loading Loading
init/README.md +6 −0 Original line number Diff line number Diff line Loading @@ -263,6 +263,12 @@ runs the service. > 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(). `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>` > 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. Loading
init/builtins.cpp +0 −15 Original line number Diff line number Diff line Loading @@ -1104,20 +1104,6 @@ static Result<void> ExecWithFunctionOnFailure(const std::vector<std::string>& ar 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) { auto reboot_reason = vdc_arg + "_failed"; Loading Loading @@ -1225,7 +1211,6 @@ const BuiltinFunctionMap& GetBuiltinFunctionMap() { {"enable", {1, 1, {false, do_enable}}}, {"exec", {1, kMax, {false, do_exec}}}, {"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}}}, {"export", {2, 2, {false, do_export}}}, {"hostname", {1, 1, {true, do_hostname}}}, Loading
init/host_init_stubs.h +5 −0 Original line number Diff line number Diff line Loading @@ -34,6 +34,11 @@ namespace android { namespace init { // init.h inline void EnterShutdown(const std::string&) { abort(); } // property_service.h inline bool CanReadProperty(const std::string&, const std::string&) { return true; Loading
init/init.cpp +11 −10 Original line number Diff line number Diff line Loading @@ -180,6 +180,16 @@ void ResetWaitForProp() { 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) { // 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 Loading @@ -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 // commands to be executed. if (name == "sys.powerctl") { // Despite the above comment, we can't call HandlePowerctlMessage() 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. // 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; EnterShutdown(value); } if (property_triggers_enabled) ActionManager::GetInstance().QueuePropertyChange(name, value); Loading
init/init.h +2 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ namespace init { Parser CreateParser(ActionManager& action_manager, 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); void DumpState(); Loading