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
This commit is contained in:
Jinguang Dong 2018-11-24 17:12:33 +08:00
parent 66a6d8877c
commit 8ac2f27cc2

View file

@ -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();