diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 2d0f56c98..a634eb17c 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -740,6 +740,7 @@ int main(int argc, char *argv[]) * valgrind will warn us if we make decisions based on uninitialized * variables. */ ld = new_lightningd(NULL); + ld->state = LD_STATE_RUNNING; /* Figure out where our daemons are first. */ ld->daemon_dir = find_daemon_dir(ld, argv[0]); @@ -931,6 +932,7 @@ int main(int argc, char *argv[]) * shut down. */ assert(io_loop_ret == ld); + ld->state = LD_STATE_SHUTDOWN; /* Keep this fd around, to write final response at the end. */ stop_fd = io_conn_fd(ld->stop_conn); diff --git a/lightningd/lightningd.h b/lightningd/lightningd.h index dcc461672..d42c8441f 100644 --- a/lightningd/lightningd.h +++ b/lightningd/lightningd.h @@ -80,6 +80,11 @@ struct config { typedef STRMAP(const char *) alt_subdaemon_map; +enum lightningd_state { + LD_STATE_RUNNING, + LD_STATE_SHUTDOWN, +}; + struct lightningd { /* The directory to find all the subdaemons. */ const char *daemon_dir; @@ -262,6 +267,8 @@ struct lightningd { struct list_head waitblockheight_commands; alt_subdaemon_map alt_subdaemons; + + enum lightningd_state state; }; /* Turning this on allows a tal allocation to return NULL, rather than aborting. diff --git a/lightningd/plugin_hook.c b/lightningd/plugin_hook.c index 9a308d13d..5551c742a 100644 --- a/lightningd/plugin_hook.c +++ b/lightningd/plugin_hook.c @@ -17,6 +17,7 @@ struct plugin_hook_request { void *cb_arg; void *payload; struct db *db; + struct lightningd *ld; }; /* A link in the plugin_hook call chain (there's a joke in there about @@ -156,6 +157,11 @@ static void plugin_hook_callback(const char *buffer, const jsmntok_t *toks, bool more_plugins, cont; struct plugin_hook_call_link *last; + if (r->ld->state == LD_STATE_SHUTDOWN) { + log_debug(r->ld->log, + "Abandoning plugin hook call due to shutdown"); + return; + } /* Pop the head off the call chain and continue with the next */ last = list_pop(&r->call_chain, struct plugin_hook_call_link, list); assert(last != NULL); @@ -232,6 +238,7 @@ void plugin_hook_call_(struct lightningd *ld, const struct plugin_hook *hook, ph_req->db = ld->wallet->db; ph_req->payload = tal_steal(ph_req, payload); ph_req->current_plugin = -1; + ph_req->ld = ld; list_head_init(&ph_req->call_chain); for (size_t i=0; iplugins); i++) {