@@ -550,10 +550,10 @@ dumpFileDescriptorInfo(AbortHandlerWorkingState &state) {
550550}
551551
552552static void
553- dumpWithCrashWatch (AbortHandlerWorkingState &state) {
553+ dumpWithCrashWatch (AbortHandlerWorkingState &state, bool toStderr ) {
554554 int fd = -1 ;
555555
556- if (state.crashLogDirFd != -1 ) {
556+ if (state.crashLogDirFd != -1 && !toStderr ) {
557557 fd = openat (state.crashLogDirFd , " backtrace.log" , O_WRONLY | O_CREAT | O_TRUNC, 0600 );
558558 if (fd != -1 ) {
559559 printCrashLogFileCreated (state, " backtrace.log" );
@@ -594,7 +594,25 @@ dumpWithCrashWatch(AbortHandlerWorkingState &state) {
594594 write_nowarn (STDERR_FILENO, state.messageBuf , pos - state.messageBuf );
595595
596596 } else {
597- waitpid (child, NULL , 0 );
597+ int status = -1 ;
598+ int ret = waitpid (child, &status, 0 );
599+ int e = errno;
600+ if (ret == -1 || status != 0 ) {
601+ pos = state.messageBuf ;
602+ pos = ASSU::appendData (pos, end, " ERROR running 'crash-watch' (" );
603+ if (ret == -1 ) {
604+ pos = ASSU::appendData (pos, end, " waitpid() failed, errno=" );
605+ pos = ASSU::appendInteger<int , 10 >(pos, end, e);
606+ } else if (WIFSIGNALED (status)) {
607+ pos = ASSU::appendData (pos, end, " exited with signal " );
608+ pos = ASSU::appendInteger<int , 10 >(pos, end, WTERMSIG (status));
609+ } else {
610+ pos = ASSU::appendData (pos, end, " exit status " );
611+ pos = ASSU::appendInteger<int , 10 >(pos, end, WEXITSTATUS (status));
612+ }
613+ pos = ASSU::appendData (pos, end, " )\n " );
614+ write_nowarn (STDERR_FILENO, state.messageBuf , pos - state.messageBuf );
615+ }
598616 }
599617
600618 if (fd != -1 ) {
@@ -852,7 +870,7 @@ dumpDiagnostics(AbortHandlerWorkingState &state) {
852870 pos = ASSU::appendData (pos, end, " ] Dumping a backtrace with crash-watch...\n " );
853871 #endif
854872 write_nowarn (STDERR_FILENO, state.messageBuf , pos - state.messageBuf );
855- dumpWithCrashWatch (state);
873+ dumpWithCrashWatch (state, ctx-> config -> dumpCrashWatchToStderr );
856874 } else {
857875 write_nowarn (STDERR_FILENO, " \n " , 1 );
858876 }
@@ -969,7 +987,7 @@ forkAndRedirectToTeeAndMainLogFile(const char *crashLogDir) {
969987 execlp (" /usr/bin/cat" , " cat" , (char *) 0 );
970988 ASSU::printError (" ERROR: cannot execute 'tee' or 'cat'; crash log will be lost!\n " );
971989 _exit (1 );
972- return false ;
990+ return false ; // Unreachable
973991 } else if (pid == -1 ) {
974992 ASSU::printError (" ERROR: cannot fork a process for executing 'tee'\n " );
975993 return false ;
0 commit comments