Browse Source

plugin: Do not forward plugin hook calls during shutdown

We make the current state of `lightningd` explicit so we don't have to
identify a shutdown by its side-effects. We then use this in order to prevent
the killing and freeing of plugins to continue down the chain of registered
plugins.
travis-debug
Christian Decker 5 years ago
committed by Rusty Russell
parent
commit
41a5728fc3
  1. 2
      lightningd/lightningd.c
  2. 7
      lightningd/lightningd.h
  3. 7
      lightningd/plugin_hook.c

2
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);

7
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.

7
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; i<tal_count(hook->plugins); i++) {

Loading…
Cancel
Save