[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
This commit is contained in:
Haobo Xu 2013-04-22 10:14:54 -07:00
parent 958b9c80e1
commit 06d3487b3f

View File

@ -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