diff options
author | Tom Cherry <tomcherry@google.com> | 2017-04-17 16:34:20 -0700 |
---|---|---|
committer | Tom Cherry <tomcherry@google.com> | 2017-04-17 16:40:06 -0700 |
commit | 98ad32a967079be80a101458d8a29d7ecefbb547 (patch) | |
tree | 64c0d213fc7c4f81f1424aa601792c5628c2989b /init/builtins.cpp | |
parent | b7826a74f246ac148c3f5c6ad73e3fc8728a0bfe (diff) |
init: handle sys.powerctl immediately
Currently if a process sets the sys.powerctl property, init adds this
property change into the event queue, just like any other property.
The actual logic to shutdown the device is not executed until init
gets to the action associated with the property change.
This is bad for multiple reasons, but explicitly causes deadlock in
the follow scenario:
A service is started with `exec` or `exec_start`
The same service sets sys.powerctl indicating to the system to
shutdown
The same service then waits infinitely
In this case, init doesn't process any further commands until the exec
service completes, including the command to reboot the device.
This change causes init to immediately handle sys.powerctl and reboot
the device regardless of the state of the event queue, wait for exec,
or wait for property conditions.
Bug: 37209359
Bug: 37415192
Test: Init reboots normally
Test: Update verifier can reboot the system
Change-Id: Iff2295aed970840f47e56c4bacc93001b791fa35
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r-- | init/builtins.cpp | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp index 2327cdfb4..43eb42075 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -598,58 +598,6 @@ static int do_restart(const std::vector<std::string>& args) { return 0; } -static int do_powerctl(const std::vector<std::string>& args) { - const std::string& command = args[1]; - unsigned int cmd = 0; - std::vector<std::string> cmd_params = android::base::Split(command, ","); - std::string reason_string = cmd_params[0]; - std::string reboot_target = ""; - bool runFsck = false; - bool commandInvalid = false; - - if (cmd_params.size() > 3) { - commandInvalid = true; - } else if (cmd_params[0] == "shutdown") { - cmd = ANDROID_RB_POWEROFF; - if (cmd_params.size() == 2 && cmd_params[1] == "userrequested") { - // The shutdown reason is PowerManager.SHUTDOWN_USER_REQUESTED. - // Run fsck once the file system is remounted in read-only mode. - runFsck = true; - reason_string = cmd_params[1]; - } - } else if (cmd_params[0] == "reboot") { - cmd = ANDROID_RB_RESTART2; - if (cmd_params.size() >= 2) { - reboot_target = cmd_params[1]; - // When rebooting to the bootloader notify the bootloader writing - // also the BCB. - if (reboot_target == "bootloader") { - std::string err; - if (!write_reboot_bootloader(&err)) { - LOG(ERROR) << "reboot-bootloader: Error writing " - "bootloader_message: " - << err; - } - } - // If there is an additional bootloader parameter, pass it along - if (cmd_params.size() == 3) { - reboot_target += "," + cmd_params[2]; - } - } - } else if (command == "thermal-shutdown") { // no additional parameter allowed - cmd = ANDROID_RB_THERMOFF; - } else { - commandInvalid = true; - } - if (commandInvalid) { - LOG(ERROR) << "powerctl: unrecognized command '" << command << "'"; - return -EINVAL; - } - - DoReboot(cmd, reason_string, reboot_target, runFsck); - return 0; -} - static int do_trigger(const std::vector<std::string>& args) { ActionManager::GetInstance().QueueEventTrigger(args[1]); return 0; @@ -919,7 +867,6 @@ BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const { {"mount_all", {1, kMax, do_mount_all}}, {"mount", {3, kMax, do_mount}}, {"umount", {1, 1, do_umount}}, - {"powerctl", {1, 1, do_powerctl}}, {"restart", {1, 1, do_restart}}, {"restorecon", {1, kMax, do_restorecon}}, {"restorecon_recursive", {1, kMax, do_restorecon_recursive}}, |