From 38ac45df1738496d5581b89845e48daeab7f0219 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Fri, 27 Apr 2018 13:31:47 -0700 Subject: [PATCH] crash_dump: defuse our signal handlers earlier. We have a LOG(FATAL) that can potentially happen before we turn off SIGABRT. Move the signal handler defusing to the very start of main. Bug: http://b/77920633 Test: treehugger Change-Id: I7a2f2a0f2bed16e54467388044eca254102aa6a0 --- debuggerd/crash_dump.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/debuggerd/crash_dump.cpp b/debuggerd/crash_dump.cpp index a1f021184..40cf6c340 100644 --- a/debuggerd/crash_dump.cpp +++ b/debuggerd/crash_dump.cpp @@ -190,6 +190,19 @@ static bool g_tombstoned_connected = false; static unique_fd g_tombstoned_socket; static unique_fd g_output_fd; +static void DefuseSignalHandlers() { + // Don't try to dump ourselves. + struct sigaction action = {}; + action.sa_handler = SIG_DFL; + debuggerd_register_handlers(&action); + + sigset_t mask; + sigemptyset(&mask); + if (sigprocmask(SIG_SETMASK, &mask, nullptr) != 0) { + PLOG(FATAL) << "failed to set signal mask"; + } +} + static void Initialize(char** argv) { android::base::InitLogging(argv); android::base::SetAborter([](const char* abort_msg) { @@ -213,17 +226,6 @@ static void Initialize(char** argv) { _exit(1); }); - - // Don't try to dump ourselves. - struct sigaction action = {}; - action.sa_handler = SIG_DFL; - debuggerd_register_handlers(&action); - - sigset_t mask; - sigemptyset(&mask); - if (sigprocmask(SIG_SETMASK, &mask, nullptr) != 0) { - PLOG(FATAL) << "failed to set signal mask"; - } } static void ParseArgs(int argc, char** argv, pid_t* pseudothread_tid, DebuggerdDumpType* dump_type) { @@ -321,6 +323,8 @@ static pid_t wait_for_vm_process(pid_t pseudothread_tid) { } int main(int argc, char** argv) { + DefuseSignalHandlers(); + atrace_begin(ATRACE_TAG, "before reparent"); pid_t target_process = getppid();