db: decouple fatal reliance, have as impl defined function

`fatal` is defined in lightningd and has logfile dependencies etc.

Make it more generic by allowing declaration in the use file (wallet.c)
This commit is contained in:
niftynei
2022-03-01 11:22:15 -06:00
committed by Rusty Russell
parent b0829fc52a
commit 03c950bae8
6 changed files with 54 additions and 37 deletions

View File

@@ -809,22 +809,25 @@ void log_backtrace_exit(void)
}
}
void fatal_vfmt(const char *fmt, va_list ap)
{
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
if (!crashlog)
exit(1);
logv(crashlog, LOG_BROKEN, NULL, true, fmt, ap);
abort();
}
void fatal(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
fatal_vfmt(fmt, ap);
va_end(ap);
if (!crashlog)
exit(1);
va_start(ap, fmt);
logv(crashlog, LOG_BROKEN, NULL, true, fmt, ap);
va_end(ap);
abort();
}
struct log_info {

View File

@@ -53,6 +53,7 @@ char *arg_log_to_file(const char *arg, struct lightningd *ld);
/* Once this is set, we dump fatal with a backtrace to this log */
extern struct log *crashlog;
void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...);
void NORETURN fatal_vfmt(const char *fmt, va_list ap);
void log_backtrace_print(const char *fmt, ...);
void log_backtrace_exit(void);