Skip to content

Commit

Permalink
We can log the mini backtrace to an fd now
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Apr 25, 2014
1 parent e494484 commit ce91e71
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions src/lib/debug.c
Expand Up @@ -433,14 +433,6 @@ void fr_fault(int sig)
goto finish;
}

#ifdef SIGUSR1
/*
* SIGUSR1 skips the callback, and the backtrace and just runs the
* panic_action.
*/
if (sig == SIGUSR1) goto skip_backtrace;
#endif

/*
* Run the callback if one was registered
*/
Expand All @@ -451,17 +443,13 @@ void fr_fault(int sig)
* idea of the area of the code we hit the issue in.
*/
#ifdef HAVE_EXECINFO
size_t frame_count, i;
void *stack[MAX_BT_FRAMES];
char **frames;
{
size_t frame_count;
void *stack[MAX_BT_FRAMES];

frame_count = backtrace(stack, MAX_BT_FRAMES);
frames = backtrace_symbols(stack, frame_count);

fprintf(log, "Backtrace of last %zu frames:\n", frame_count);
for (i = 0; i < frame_count; i++) {
fprintf(log, "%s\n", frames[i]);
/* Leak the backtrace strings, freeing may lead to undefined behaviour... */
frame_count = backtrace(stack, MAX_BT_FRAMES);
fprintf(log, "Backtrace of last %zu frames:\n", frame_count);
backtrace_symbols_fd(stack, frame_count, fr_fault_log_fd);
}
#endif

Expand Down Expand Up @@ -491,7 +479,10 @@ void fr_fault(int sig)
fprintf(log, "Panic action exited with %i\n", code);

#ifdef SIGUSR1
if (sig == SIGUSR1) return;
if (sig == SIGUSR1) {
fclose(log);
return;
}
#endif

finish:
Expand Down

0 comments on commit ce91e71

Please sign in to comment.