mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
patch db-fatal-plugin_err.patch
This commit is contained in:
@@ -13,6 +13,8 @@ struct migration {
|
||||
void (*func)(struct plugin *p, struct db *db);
|
||||
};
|
||||
|
||||
static struct plugin *plugin;
|
||||
|
||||
/* Do not reorder or remove elements from this array.
|
||||
* It is used to migrate existing databases from a prevoius state, based on
|
||||
* string indicies */
|
||||
@@ -136,21 +138,21 @@ static bool db_migrate(struct plugin *p, struct db *db)
|
||||
void db_fatal(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
plugin_errv(plugin, fmt, ap);
|
||||
/* Won't actually exit, but va_end() required to balance va_start in standard. */
|
||||
va_end(ap);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
#endif /* DB_FATAL */
|
||||
|
||||
struct db *db_setup(const tal_t *ctx, struct plugin *p, char *db_dsn)
|
||||
{
|
||||
bool migrated;
|
||||
struct db *db = db_open(ctx, db_dsn);
|
||||
struct db *db;
|
||||
|
||||
/* Set global for db_fatal */
|
||||
plugin = p;
|
||||
db = db_open(ctx, db_dsn);
|
||||
db->report_changes_fn = NULL;
|
||||
|
||||
db_begin_transaction(db);
|
||||
|
||||
@@ -1288,18 +1288,26 @@ void NORETURN plugin_exit(struct plugin *p, int exitcode)
|
||||
exit(exitcode);
|
||||
}
|
||||
|
||||
void NORETURN plugin_errv(struct plugin *p, const char *fmt, va_list ap)
|
||||
{
|
||||
va_list ap2;
|
||||
|
||||
/* In case it gets consumed, make a copy. */
|
||||
va_copy(ap2, ap);
|
||||
|
||||
plugin_logv(p, LOG_BROKEN, fmt, ap);
|
||||
vfprintf(stderr, fmt, ap2);
|
||||
plugin_exit(p, 1);
|
||||
va_end(ap2);
|
||||
}
|
||||
|
||||
void NORETURN plugin_err(struct plugin *p, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
plugin_logv(p, LOG_BROKEN, fmt, ap);
|
||||
plugin_errv(p, fmt, ap);
|
||||
va_end(ap);
|
||||
va_start(ap, fmt);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
plugin_exit(p, 1);
|
||||
}
|
||||
|
||||
void plugin_log(struct plugin *p, enum log_level l, const char *fmt, ...)
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <common/node_id.h>
|
||||
#include <common/status_levels.h>
|
||||
#include <common/utils.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
struct json_out;
|
||||
struct plugin;
|
||||
@@ -226,6 +227,9 @@ struct command_result *command_param_failed(void);
|
||||
/* Call this on fatal error. */
|
||||
void NORETURN plugin_err(struct plugin *p, const char *fmt, ...);
|
||||
|
||||
/* Call this on fatal error. */
|
||||
void NORETURN plugin_errv(struct plugin *p, const char *fmt, va_list ap);
|
||||
|
||||
/* Normal exit (makes sure to flush output!). */
|
||||
void NORETURN plugin_exit(struct plugin *p, int exitcode);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user