mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
lightningd: dump backtrace on crash or fatal().
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
dba27188b7
commit
db19873ee4
@ -211,7 +211,7 @@ int main(int argc, char *argv[])
|
||||
newdir = handle_opts(ld, argc, argv);
|
||||
|
||||
/* Activate crash log now we're in the right place. */
|
||||
crashlog_activate(ld->log);
|
||||
crashlog_activate(argv[0], ld->log);
|
||||
|
||||
/* Ignore SIGPIPE: we look at our write return values*/
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "log.h"
|
||||
#include <backtrace.h>
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <ccan/list/list.h>
|
||||
#include <ccan/opt/opt.h>
|
||||
@ -17,6 +18,8 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static struct backtrace_state *backtrace_state;
|
||||
|
||||
struct log_entry {
|
||||
struct list_node list;
|
||||
struct timeabs time;
|
||||
@ -411,6 +414,15 @@ void opt_register_logging(struct log *log)
|
||||
"log to file instead of stdout");
|
||||
}
|
||||
|
||||
static int log_backtrace(void *log, uintptr_t pc,
|
||||
const char *filename, int lineno,
|
||||
const char *function)
|
||||
{
|
||||
log_broken(log, "backtrace: %s:%u (%s) %p",
|
||||
filename, lineno, function, (void *)pc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct log *crashlog;
|
||||
|
||||
/* FIXME: Dump peer logs! */
|
||||
@ -419,8 +431,9 @@ static void log_crash(int sig)
|
||||
const char *logfile = NULL;
|
||||
|
||||
if (sig) {
|
||||
/* FIXME: Backtrace! */
|
||||
log_broken(crashlog, "FATAL SIGNAL %i RECEIVED", sig);
|
||||
backtrace_full(backtrace_state, 0, log_backtrace, NULL,
|
||||
crashlog);
|
||||
}
|
||||
|
||||
if (crashlog->lr->print == log_default_print) {
|
||||
@ -442,18 +455,21 @@ static void log_crash(int sig)
|
||||
logfile = NULL;
|
||||
}
|
||||
|
||||
if (sig)
|
||||
if (sig) {
|
||||
fprintf(stderr, "Fatal signal %u. ", sig);
|
||||
backtrace_print(backtrace_state, 0, stderr);
|
||||
}
|
||||
if (logfile)
|
||||
fprintf(stderr, "Log dumped in %s", logfile);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
void crashlog_activate(struct log *log)
|
||||
void crashlog_activate(const char *argv0, struct log *log)
|
||||
{
|
||||
struct sigaction sa;
|
||||
crashlog = log;
|
||||
|
||||
backtrace_state = backtrace_create_state(argv0, 0, NULL, NULL);
|
||||
sa.sa_handler = log_crash;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
/* We want to fall through to default handler */
|
||||
|
@ -87,7 +87,7 @@ void log_each_line_(const struct log_book *lr,
|
||||
|
||||
void log_dump_to_file(int fd, const struct log_book *lr);
|
||||
void opt_register_logging(struct log *log);
|
||||
void crashlog_activate(struct log *log);
|
||||
void crashlog_activate(const char *argv0, struct log *log);
|
||||
|
||||
/* Convenience parent for temporary allocations (eg. type_to_string)
|
||||
* during log calls; freed after every log_*() */
|
||||
|
Loading…
Reference in New Issue
Block a user