From 636ebc9b3b2ecbfd4bb56714d04f2526dc0251fa Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Mon, 7 Oct 2019 18:16:23 -0700 Subject: [PATCH] init: actually report which signal is causing the reboot. It wasn't clear to me why init was rebooting until I saw that it was SIGABRT, which then made me read through earlier log spam to work out what was actually unhappy (the SELinux compiler, in my case). Test: worked out why init was rebooting my device Change-Id: I605d8956213c4c23711073fd4b0ff99562b7f351 --- init/host_init_stubs.h | 2 +- init/reboot_utils.cpp | 5 +++-- init/reboot_utils.h | 2 +- init/util.cpp | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/init/host_init_stubs.h b/init/host_init_stubs.h index e3068b224..71f78a558 100644 --- a/init/host_init_stubs.h +++ b/init/host_init_stubs.h @@ -55,7 +55,7 @@ inline uint32_t HandlePropertySet(const std::string&, const std::string&, const // reboot_utils.h inline void SetFatalRebootTarget() {} -inline void __attribute__((noreturn)) InitFatalReboot() { +inline void __attribute__((noreturn)) InitFatalReboot(int signal_number) { abort(); } diff --git a/init/reboot_utils.cpp b/init/reboot_utils.cpp index de085cc9b..dac0cf4ae 100644 --- a/init/reboot_utils.cpp +++ b/init/reboot_utils.cpp @@ -109,7 +109,7 @@ void __attribute__((noreturn)) RebootSystem(unsigned int cmd, const std::string& abort(); } -void __attribute__((noreturn)) InitFatalReboot() { +void __attribute__((noreturn)) InitFatalReboot(int signal_number) { auto pid = fork(); if (pid == -1) { @@ -124,6 +124,7 @@ void __attribute__((noreturn)) InitFatalReboot() { } // In the parent, let's try to get a backtrace then shutdown. + LOG(ERROR) << __FUNCTION__ << ": signal " << signal_number; std::unique_ptr backtrace( Backtrace::Create(BACKTRACE_CURRENT_PROCESS, BACKTRACE_CURRENT_THREAD)); if (!backtrace->Unwind(0)) { @@ -154,7 +155,7 @@ void InstallRebootSignalHandlers() { // RebootSystem uses syscall() which isn't actually async-signal-safe, but our only option // and probably good enough given this is already an error case and only enabled for // development builds. - InitFatalReboot(); + InitFatalReboot(signal); }; action.sa_flags = SA_RESTART; sigaction(SIGABRT, &action, nullptr); diff --git a/init/reboot_utils.h b/init/reboot_utils.h index 3fd969e69..878ad9696 100644 --- a/init/reboot_utils.h +++ b/init/reboot_utils.h @@ -27,7 +27,7 @@ void SetFatalRebootTarget(); bool IsRebootCapable(); // This is a wrapper around the actual reboot calls. void __attribute__((noreturn)) RebootSystem(unsigned int cmd, const std::string& reboot_target); -void __attribute__((noreturn)) InitFatalReboot(); +void __attribute__((noreturn)) InitFatalReboot(int signal_number); void InstallRebootSignalHandlers(); } // namespace init diff --git a/init/util.cpp b/init/util.cpp index 053237509..40db838d4 100644 --- a/init/util.cpp +++ b/init/util.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -481,7 +482,7 @@ static void InitAborter(const char* abort_message) { return; } - InitFatalReboot(); + InitFatalReboot(SIGABRT); } // The kernel opens /dev/console and uses that fd for stdin/stdout/stderr if there is a serial