From 1ef79854c3255da41e19335ebb9ce24973870f1d Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Mon, 5 Feb 2018 21:25:54 +0100 Subject: [PATCH] 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 --- lightningd/log.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lightningd/log.c b/lightningd/log.c index 21b2e1e4e..1b37243e2 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -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); }