diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-02-15 21:16:42 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-02-15 21:16:42 +0000 |
commit | 851803d3cf3e874bb9305341a681a56cc73e7c57 (patch) | |
tree | 7a738bb4f95a8b2a843e3f4cb2f3ad0aa841c298 /init/builtins.cpp | |
parent | e1ae2ff9e46547dfaa3947eedd5e471332c92a86 (diff) | |
parent | 959b05553576ffc15da4334a5917ce763611ab82 (diff) |
Merge "If enablefilecrypto or init_user0 fails, reboot into recovery."
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r-- | init/builtins.cpp | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp index 5d924b1ff..1040b47b0 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -285,11 +285,8 @@ static Result<Success> do_mkdir(const BuiltinArguments& args) { if (e4crypt_is_native()) { if (e4crypt_set_directory_policy(args[1].c_str())) { - const std::vector<std::string> options = { - "--prompt_and_wipe_data", - "--reason=set_policy_failed:"s + args[1]}; - reboot_into_recovery(options); - return Success(); + reboot_into_recovery( + {"--prompt_and_wipe_data", "--reason=set_policy_failed:"s + args[1]}); } } return Success(); @@ -987,6 +984,24 @@ static bool is_file_crypto() { return android::base::GetProperty("ro.crypto.type", "") == "file"; } +static Result<Success> ExecWithRebootOnFailure(const std::string& reboot_reason, + const std::vector<std::string>& args) { + auto service = Service::MakeTemporaryOneshotService(args); + if (!service) { + return Error() << "Could not create exec service"; + } + service->AddReapCallback([reboot_reason](const siginfo_t& siginfo) { + if (siginfo.si_code != CLD_EXITED || siginfo.si_status != 0) { + reboot_into_recovery({"--prompt_and_wipe_data", "--reason="s + reboot_reason}); + } + }); + if (auto result = service->ExecStart(); !result) { + return Error() << "Could not start exec service: " << result.error(); + } + ServiceList::GetInstance().AddService(std::move(service)); + return Success(); +} + static Result<Success> do_installkey(const BuiltinArguments& args) { if (!is_file_crypto()) return Success(); @@ -994,15 +1009,13 @@ static Result<Success> do_installkey(const BuiltinArguments& args) { if (!make_dir(unencrypted_dir, 0700) && errno != EEXIST) { return ErrnoError() << "Failed to create " << unencrypted_dir; } - std::vector<std::string> exec_args = {"exec", "/system/bin/vdc", "--wait", "cryptfs", - "enablefilecrypto"}; - return do_exec({std::move(exec_args), args.context}); + return ExecWithRebootOnFailure("enablefilecrypto_failed", {"exec", "/system/bin/vdc", "--wait", + "cryptfs", "enablefilecrypto"}); } static Result<Success> do_init_user0(const BuiltinArguments& args) { - std::vector<std::string> exec_args = {"exec", "/system/bin/vdc", "--wait", "cryptfs", - "init_user0"}; - return do_exec({std::move(exec_args), args.context}); + return ExecWithRebootOnFailure("init_user0_failed", + {"exec", "/system/bin/vdc", "--wait", "cryptfs", "init_user0"}); } const BuiltinFunctionMap::Map& BuiltinFunctionMap::map() const { |