From 8ac2f27cc2fa5fbfc1bbd1cede906d254a77f862 Mon Sep 17 00:00:00 2001 From: Jinguang Dong Date: Sat, 24 Nov 2018 17:12:33 +0800 Subject: [PATCH] tombstoned: fixed tombstones failed issue There is a problem about tombstone, which it will fail to generate tombstone file in some scenarios due to socket communication exception. Reproduce step: step 1: reboot device step 2: ps -ef |grep zygote , get the pid of zygote64 (Attention: zygote64 should never been killed or reboot, otherwise we can get the tombstone file) step 3: kill -5 pid of zygote64 step 4: cd data/tombstones/, and could not find the tombstone file of zygote64. [Cause Analysis] 1. There are following logs by logcat: 11-19 15:38:43.789 569 569 F libc : Fatal signal 5 (SIGTRAP), code 0 (SI_USER) in tid 569 (main), pid 569 (main) 11-19 15:38:43.829 6115 6115 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstone 11-19 15:38:43.830 569 5836 I Zygote : Process 6114 exited cleanly (0) 11-19 15:38:43.830 777 777 I /system/bin/tombstoned: received crash request for pid 569 11-19 15:38:43.831 6115 6115 I crash_dump64: performing dump of process 569 (target tid = 569) ... 11-19 15:38:43.937 777 777 W /system/bin/tombstoned: crash socket received short read of length 0 (expected 12) 2. The last log was print by function of crash_request_cb in file of tombstoned.cpp, following related code: rc = TEMP_FAILURE_RETRY(read(sockfd, &request, sizeof(request))); if (rc == -1) { PLOG(WARNING) << "failed to read from crash socket"; goto fail; } else if (rc != sizeof(request)) { LOG(WARNING) << "crash socket received short read of length " << rc << " (expected " << sizeof(request) << ")"; goto fail; } Tombstoned read message by socket, and now the message length is zero. Some socket communication exception occurs at that time. We try to let crash_dump resend the socket message when the communication is abnormal. Just as this CL. Test: 1 reboot device 2 ps -ef |grep zygote , get the pid of zygote64 (Attention: zygote64 should never been killed or reboot, otherwise we can get the tombstone file) 3 kill -5 pid of zygote64 4 cd data/tombstones/, and could find the tombstone file of zygote64. Change-Id: Ic152b081024d6c12f757927079fd221b63445b18 --- debuggerd/crash_dump.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/debuggerd/crash_dump.cpp b/debuggerd/crash_dump.cpp index 577e336b0..d79d20b8a 100644 --- a/debuggerd/crash_dump.cpp +++ b/debuggerd/crash_dump.cpp @@ -348,8 +348,16 @@ static pid_t wait_for_vm_process(pid_t pseudothread_tid) { return vm_pid; } +static void InstallSigPipeHandler() { + struct sigaction action = {}; + action.sa_handler = SIG_IGN; + action.sa_flags = SA_RESTART; + sigaction(SIGPIPE, &action, nullptr); +} + int main(int argc, char** argv) { DefuseSignalHandlers(); + InstallSigPipeHandler(); atrace_begin(ATRACE_TAG, "before reparent"); pid_t target_process = getppid();