From c4700a13a7656282d2eb975d5c3bdfb0de2ab06d Mon Sep 17 00:00:00 2001 From: conanoc Date: Thu, 22 Mar 2018 16:10:23 +0900 Subject: [PATCH] Add guard for BACKTRACE_SUPPORTED --- common/subdaemon.c | 5 +++++ external/Makefile | 3 ++- lightningd/log.c | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/common/subdaemon.c b/common/subdaemon.c index d032eb4e6..8301068ff 100644 --- a/common/subdaemon.c +++ b/common/subdaemon.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -12,6 +13,7 @@ #include #include +#if BACKTRACE_SUPPORTED static struct backtrace_state *backtrace_state; static int backtrace_status(void *unused UNUSED, uintptr_t pc, @@ -51,6 +53,7 @@ static void crashlog_activate(void) sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } +#endif #if DEVELOPER extern volatile bool debugger_connected; @@ -65,8 +68,10 @@ void subdaemon_setup(int argc, char *argv[]) } err_set_progname(argv[0]); +#if BACKTRACE_SUPPORTED backtrace_state = backtrace_create_state(argv[0], 0, NULL, NULL); crashlog_activate(); +#endif /* We handle write returning errors! */ signal(SIGPIPE, SIG_IGN); diff --git a/external/Makefile b/external/Makefile index 704a36d16..5dddf8902 100644 --- a/external/Makefile +++ b/external/Makefile @@ -16,7 +16,8 @@ EXTERNAL_INCLUDE_FLAGS := \ -I external/libwally-core/src/secp256k1/include/ \ -I external/jsmn/ \ -I external/libbase58/ \ - -I external/libbacktrace + -I external/libbacktrace/ \ + -I external/libbacktrace-build EXTERNAL_LDLIBS := -Lexternal $(patsubst lib%.a,-l%,$(notdir $(EXTERNAL_LIBS))) diff --git a/lightningd/log.c b/lightningd/log.c index a8371651e..fb23d6069 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -1,5 +1,6 @@ #include "log.h" #include +#include #include #include #include @@ -463,6 +464,7 @@ void opt_register_logging(struct lightningd *ld) "log to file instead of stdout"); } +#if BACKTRACE_SUPPORTED static int log_backtrace(void *log, uintptr_t pc, const char *filename, int lineno, const char *function) @@ -521,9 +523,11 @@ static void log_crash(int sig) fprintf(stderr, "Log dumped in %s", logfile); fprintf(stderr, "\n"); } +#endif void crashlog_activate(const char *argv0 UNUSED, struct log *log) { +#if BACKTRACE_SUPPORTED struct sigaction sa; crashlog = log; @@ -536,6 +540,7 @@ void crashlog_activate(const char *argv0 UNUSED, struct log *log) sigaction(SIGFPE, &sa, NULL); sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); +#endif } void log_dump_to_file(int fd, const struct log_book *lr) @@ -575,6 +580,7 @@ void fatal(const char *fmt, ...) fprintf(stderr, "\n"); va_end(ap); +#if BACKTRACE_SUPPORTED /* Early on, we just dump errors to stderr. */ if (crashlog) { va_start(ap, fmt); @@ -582,6 +588,7 @@ void fatal(const char *fmt, ...) va_end(ap); log_crash(0); } +#endif abort(); }