From 06d3487b3fba1a3ed4f5041c7e6be38cc6dff4a3 Mon Sep 17 00:00:00 2001 From: Haobo Xu Date: Mon, 22 Apr 2013 10:14:54 -0700 Subject: [PATCH] [RocksDB] Print stack trace to stderr instead of stdio. Summary: Some scripts (like regression_build_test.sh) redirect stdio to a tmp file and delete it on exit. This would miss the stack trace output on segfault. Output to stderr would hopefully show us the stack trace in the continuous build output. Test Plan: ./signal_test, make check Reviewers: dhruba Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D10485 --- port/stack_trace.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/port/stack_trace.cc b/port/stack_trace.cc index d9f41881f..039500999 100644 --- a/port/stack_trace.cc +++ b/port/stack_trace.cc @@ -30,7 +30,7 @@ static void StackTraceHandler(int sig) { // reset to default handler signal(sig, SIG_DFL); - printf("Received signal %d (%s)\n", sig, strsignal(sig)); + fprintf(stderr, "Received signal %d (%s)\n", sig, strsignal(sig)); const int kMaxFrames = 100; void *frames[kMaxFrames]; @@ -44,9 +44,9 @@ static void StackTraceHandler(int sig) { for (int i = kSkip; i < num_frames; ++i) { - printf("#%-2d %p ", i - kSkip, frames[i]); + fprintf(stderr, "#%-2d %p ", i - kSkip, frames[i]); if (symbols) { - printf("%s ", symbols[i]); + fprintf(stderr, "%s ", symbols[i]); } if (executable) { // out source to addr2line, for the address translation @@ -57,14 +57,14 @@ static void StackTraceHandler(int sig) { if (f) { char line[kLineMax]; while (fgets(line, sizeof(line), f)) { - printf("%s", line); + fprintf(stderr, "%s", line); } pclose(f); } else { - printf("\n"); + fprintf(stderr, "\n"); } } else { - printf("\n"); + fprintf(stderr, "\n"); } } @@ -79,6 +79,9 @@ void InstallStackTraceHandler() { signal(SIGSEGV, StackTraceHandler); signal(SIGBUS, StackTraceHandler); signal(SIGABRT, StackTraceHandler); + + printf("Installed stack trace handler for SIGILL SIGSEGV SIGBUS SIGABRT\n"); + } } // namespace leveldb