lightningd: Don't crash when libunwind backtrace not available

libunwind does not accept a NULL parameter for the error callback. It
will simply call into the NULL pointer. So add an error callback.

This makes the crash output somewhat more sensible on FreeBSD, where
there is no libunwind stack trace available:

    2018-02-05T20:24:50.598Z lightningd(75556): error getting backtrace: no stack trace because unwind library not available (0)

Signed-off-by: Wladimir J. van der Laan <laanwj@gmail.com>
This commit is contained in:
Wladimir J. van der Laan 2018-02-05 21:25:54 +01:00 committed by Rusty Russell
parent 7dd19d5b93
commit 1ef79854c3
1 changed files with 8 additions and 1 deletions

View File

@ -453,6 +453,13 @@ static int log_backtrace(void *log, uintptr_t pc,
return 0;
}
static void log_backtrace_error(void *log, const char *msg,
int errnum)
{
log_broken(log, "error getting backtrace: %s (%d)",
msg, errnum);
}
static struct log *crashlog;
/* FIXME: Dump peer logs! */
@ -463,7 +470,7 @@ static void log_crash(int sig)
if (sig) {
log_broken(crashlog, "FATAL SIGNAL %i RECEIVED", sig);
if (backtrace_state)
backtrace_full(backtrace_state, 0, log_backtrace, NULL,
backtrace_full(backtrace_state, 0, log_backtrace, log_backtrace_error,
crashlog);
}