diff --git a/lightningd/log.c b/lightningd/log.c index 15601c0b3..efc3f8389 100644 --- a/lightningd/log.c +++ b/lightningd/log.c @@ -18,6 +18,10 @@ #include #include +#if DEVELOPER +bool dev_no_backtrace; +#endif + static struct backtrace_state *backtrace_state; struct log_entry { @@ -432,8 +436,9 @@ static void log_crash(int sig) if (sig) { log_broken(crashlog, "FATAL SIGNAL %i RECEIVED", sig); - backtrace_full(backtrace_state, 0, log_backtrace, NULL, - crashlog); + if (backtrace_state) + backtrace_full(backtrace_state, 0, log_backtrace, NULL, + crashlog); } if (crashlog->lr->print == log_default_print) { @@ -457,7 +462,8 @@ static void log_crash(int sig) if (sig) { fprintf(stderr, "Fatal signal %u. ", sig); - backtrace_print(backtrace_state, 0, stderr); + if (backtrace_state) + backtrace_print(backtrace_state, 0, stderr); } if (logfile) fprintf(stderr, "Log dumped in %s", logfile); @@ -469,6 +475,9 @@ void crashlog_activate(const char *argv0, struct log *log) struct sigaction sa; crashlog = log; +#if DEVELOPER + if (!dev_no_backtrace) +#endif backtrace_state = backtrace_create_state(argv0, 0, NULL, NULL); sa.sa_handler = log_crash; sigemptyset(&sa.sa_mask); diff --git a/lightningd/log.h b/lightningd/log.h index c0d788a28..46aa53734 100644 --- a/lightningd/log.h +++ b/lightningd/log.h @@ -94,4 +94,8 @@ const tal_t *ltmp; /* Before the crashlog is activated, just prints to stderr. */ void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...); + +#if DEVELOPER +extern bool dev_no_backtrace; +#endif #endif /* LIGHTNING_LIGHTNINGD_LOG_H */ diff --git a/lightningd/options.c b/lightningd/options.c index dcfd2bfd7..42ba6657b 100644 --- a/lightningd/options.c +++ b/lightningd/options.c @@ -288,6 +288,9 @@ static void dev_register_opts(struct lightningd *ld) NULL, ld, "File containing disconnection points"); opt_register_arg("--dev-hsm-seed=", opt_set_hsm_seed, NULL, ld, "Hex-encoded seed for HSM"); + opt_register_noarg("--dev-no-backtrace", opt_set_bool, + &dev_no_backtrace, + "Disable backtrace (crashes under valgrind)"); } #endif diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index e3698c7b7..dd9db76fe 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -107,6 +107,8 @@ class NodeFactory(object): daemon.cmd_line.append("--dev-disconnect=dev_disconnect") if DEVELOPER: daemon.cmd_line.append("--dev-fail-on-subdaemon-fail") + if VALGRIND: + daemon.cmd_line.append("--dev-no-backtrace") opts = [] if options is None else options for opt in opts: daemon.cmd_line.append(opt)