Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.pb
*.gcda
*.gcno
*.dSYM
TAGS
ccan/tools/configurator/configurator
ccan/ccan/cdump/tools/cdump-enumstr
Expand Down
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
[submodule "external/libwally-core"]
path = external/libwally-core
url = https://github.com/ElementsProject/libwally-core.git
ignore = dirty
5 changes: 5 additions & 0 deletions common/subdaemon.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <backtrace-supported.h>
#include <backtrace.h>
#include <ccan/err/err.h>
#include <ccan/str/str.h>
Expand All @@ -12,6 +13,7 @@
#include <sys/types.h>
#include <unistd.h>

#if BACKTRACE_SUPPORTED
static struct backtrace_state *backtrace_state;

static int backtrace_status(void *unused UNUSED, uintptr_t pc,
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion external/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
7 changes: 7 additions & 0 deletions lightningd/log.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "log.h"
#include <backtrace-supported.h>
#include <backtrace.h>
#include <ccan/array_size/array_size.h>
#include <ccan/list/list.h>
Expand Down Expand Up @@ -464,6 +465,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)
Expand Down Expand Up @@ -522,9 +524,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;

Expand All @@ -537,6 +541,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)
Expand Down Expand Up @@ -576,13 +581,15 @@ 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);
logv(crashlog, LOG_BROKEN, fmt, ap);
va_end(ap);
log_crash(0);
}
#endif
abort();
}

Expand Down