Loading init/builtins.cpp +11 −24 Original line number Diff line number Diff line Loading @@ -285,8 +285,11 @@ static Result<Success> do_mkdir(const BuiltinArguments& args) { if (e4crypt_is_native()) { if (e4crypt_set_directory_policy(args[1].c_str())) { reboot_into_recovery( {"--prompt_and_wipe_data", "--reason=set_policy_failed:"s + args[1]}); const std::vector<std::string> options = { "--prompt_and_wipe_data", "--reason=set_policy_failed:"s + args[1]}; reboot_into_recovery(options); return Success(); } } return Success(); Loading Loading @@ -984,24 +987,6 @@ 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(); Loading @@ -1009,13 +994,15 @@ static Result<Success> do_installkey(const BuiltinArguments& args) { if (!make_dir(unencrypted_dir, 0700) && errno != EEXIST) { return ErrnoError() << "Failed to create " << unencrypted_dir; } return ExecWithRebootOnFailure("enablefilecrypto_failed", {"exec", "/system/bin/vdc", "--wait", "cryptfs", "enablefilecrypto"}); std::vector<std::string> exec_args = {"exec", "/system/bin/vdc", "--wait", "cryptfs", "enablefilecrypto"}; return do_exec({std::move(exec_args), args.context}); } static Result<Success> do_init_user0(const BuiltinArguments& args) { return ExecWithRebootOnFailure("init_user0_failed", {"exec", "/system/bin/vdc", "--wait", "cryptfs", "init_user0"}); std::vector<std::string> exec_args = {"exec", "/system/bin/vdc", "--wait", "cryptfs", "init_user0"}; return do_exec({std::move(exec_args), args.context}); } // Builtin-function-map start Loading init/service.cpp +1 −5 Original line number Diff line number Diff line Loading @@ -303,7 +303,7 @@ void Service::SetProcessAttributes() { } } void Service::Reap(const siginfo_t& siginfo) { void Service::Reap() { if (!(flags_ & SVC_ONESHOT) || (flags_ & SVC_RESTART)) { KillProcessGroup(SIGKILL); } Loading @@ -312,10 +312,6 @@ void Service::Reap(const siginfo_t& siginfo) { std::for_each(descriptors_.begin(), descriptors_.end(), std::bind(&DescriptorInfo::Clean, std::placeholders::_1)); for (const auto& f : reap_callbacks_) { f(siginfo); } if (flags_ & SVC_EXEC) UnSetExec(); if (flags_ & SVC_TEMPORARY) return; Loading init/service.h +1 −7 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ #ifndef _INIT_SERVICE_H #define _INIT_SERVICE_H #include <signal.h> #include <sys/resource.h> #include <sys/types.h> Loading Loading @@ -82,7 +81,7 @@ class Service { void Stop(); void Terminate(); void Restart(); void Reap(const siginfo_t& siginfo); void Reap(); void DumpState() const; void SetShutdownCritical() { flags_ |= SVC_SHUTDOWN_CRITICAL; } bool IsShutdownCritical() const { return (flags_ & SVC_SHUTDOWN_CRITICAL) != 0; } Loading @@ -90,9 +89,6 @@ class Service { is_exec_service_running_ = false; flags_ &= ~SVC_EXEC; } void AddReapCallback(std::function<void(const siginfo_t& siginfo)> callback) { reap_callbacks_.emplace_back(std::move(callback)); } static bool is_exec_service_running() { return is_exec_service_running_; } Loading Loading @@ -214,8 +210,6 @@ class Service { std::vector<std::pair<int, rlimit>> rlimits_; std::vector<std::string> args_; std::vector<std::function<void(const siginfo_t& siginfo)>> reap_callbacks_; }; class ServiceList { Loading init/sigchld_handler.cpp +6 −5 Original line number Diff line number Diff line Loading @@ -84,15 +84,16 @@ static bool ReapOneProcess() { } } if (siginfo.si_code == CLD_EXITED) { LOG(INFO) << name << " exited with status " << siginfo.si_status << wait_string; } else { LOG(INFO) << name << " received signal " << siginfo.si_status << wait_string; auto status = siginfo.si_status; if (WIFEXITED(status)) { LOG(INFO) << name << " exited with status " << WEXITSTATUS(status) << wait_string; } else if (WIFSIGNALED(status)) { LOG(INFO) << name << " killed by signal " << WTERMSIG(status) << wait_string; } if (!service) return true; service->Reap(siginfo); service->Reap(); if (service->flags() & SVC_TEMPORARY) { ServiceList::GetInstance().RemoveService(*service); Loading Loading
init/builtins.cpp +11 −24 Original line number Diff line number Diff line Loading @@ -285,8 +285,11 @@ static Result<Success> do_mkdir(const BuiltinArguments& args) { if (e4crypt_is_native()) { if (e4crypt_set_directory_policy(args[1].c_str())) { reboot_into_recovery( {"--prompt_and_wipe_data", "--reason=set_policy_failed:"s + args[1]}); const std::vector<std::string> options = { "--prompt_and_wipe_data", "--reason=set_policy_failed:"s + args[1]}; reboot_into_recovery(options); return Success(); } } return Success(); Loading Loading @@ -984,24 +987,6 @@ 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(); Loading @@ -1009,13 +994,15 @@ static Result<Success> do_installkey(const BuiltinArguments& args) { if (!make_dir(unencrypted_dir, 0700) && errno != EEXIST) { return ErrnoError() << "Failed to create " << unencrypted_dir; } return ExecWithRebootOnFailure("enablefilecrypto_failed", {"exec", "/system/bin/vdc", "--wait", "cryptfs", "enablefilecrypto"}); std::vector<std::string> exec_args = {"exec", "/system/bin/vdc", "--wait", "cryptfs", "enablefilecrypto"}; return do_exec({std::move(exec_args), args.context}); } static Result<Success> do_init_user0(const BuiltinArguments& args) { return ExecWithRebootOnFailure("init_user0_failed", {"exec", "/system/bin/vdc", "--wait", "cryptfs", "init_user0"}); std::vector<std::string> exec_args = {"exec", "/system/bin/vdc", "--wait", "cryptfs", "init_user0"}; return do_exec({std::move(exec_args), args.context}); } // Builtin-function-map start Loading
init/service.cpp +1 −5 Original line number Diff line number Diff line Loading @@ -303,7 +303,7 @@ void Service::SetProcessAttributes() { } } void Service::Reap(const siginfo_t& siginfo) { void Service::Reap() { if (!(flags_ & SVC_ONESHOT) || (flags_ & SVC_RESTART)) { KillProcessGroup(SIGKILL); } Loading @@ -312,10 +312,6 @@ void Service::Reap(const siginfo_t& siginfo) { std::for_each(descriptors_.begin(), descriptors_.end(), std::bind(&DescriptorInfo::Clean, std::placeholders::_1)); for (const auto& f : reap_callbacks_) { f(siginfo); } if (flags_ & SVC_EXEC) UnSetExec(); if (flags_ & SVC_TEMPORARY) return; Loading
init/service.h +1 −7 Original line number Diff line number Diff line Loading @@ -17,7 +17,6 @@ #ifndef _INIT_SERVICE_H #define _INIT_SERVICE_H #include <signal.h> #include <sys/resource.h> #include <sys/types.h> Loading Loading @@ -82,7 +81,7 @@ class Service { void Stop(); void Terminate(); void Restart(); void Reap(const siginfo_t& siginfo); void Reap(); void DumpState() const; void SetShutdownCritical() { flags_ |= SVC_SHUTDOWN_CRITICAL; } bool IsShutdownCritical() const { return (flags_ & SVC_SHUTDOWN_CRITICAL) != 0; } Loading @@ -90,9 +89,6 @@ class Service { is_exec_service_running_ = false; flags_ &= ~SVC_EXEC; } void AddReapCallback(std::function<void(const siginfo_t& siginfo)> callback) { reap_callbacks_.emplace_back(std::move(callback)); } static bool is_exec_service_running() { return is_exec_service_running_; } Loading Loading @@ -214,8 +210,6 @@ class Service { std::vector<std::pair<int, rlimit>> rlimits_; std::vector<std::string> args_; std::vector<std::function<void(const siginfo_t& siginfo)>> reap_callbacks_; }; class ServiceList { Loading
init/sigchld_handler.cpp +6 −5 Original line number Diff line number Diff line Loading @@ -84,15 +84,16 @@ static bool ReapOneProcess() { } } if (siginfo.si_code == CLD_EXITED) { LOG(INFO) << name << " exited with status " << siginfo.si_status << wait_string; } else { LOG(INFO) << name << " received signal " << siginfo.si_status << wait_string; auto status = siginfo.si_status; if (WIFEXITED(status)) { LOG(INFO) << name << " exited with status " << WEXITSTATUS(status) << wait_string; } else if (WIFSIGNALED(status)) { LOG(INFO) << name << " killed by signal " << WTERMSIG(status) << wait_string; } if (!service) return true; service->Reap(siginfo); service->Reap(); if (service->flags() & SVC_TEMPORARY) { ServiceList::GetInstance().RemoveService(*service); Loading