From 79d32ec2f29357463ca067b167c888eebaf4b124 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 29 Jul 2019 17:00:51 +0930 Subject: [PATCH] plugin: notice when plugin has *started* configuring. Signed-off-by: Rusty Russell --- lightningd/plugin.c | 10 ++++++---- lightningd/plugin.h | 10 +++++++++- lightningd/plugin_control.c | 3 ++- tests/test_plugin.py | 1 - 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index bc9f1667f..0bb31a457 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -66,7 +66,7 @@ void plugin_register(struct plugins *plugins, const char* path TAKES) list_add_tail(&plugins->plugins, &p->list); p->plugins = plugins; p->cmd = tal_strdup(p, path); - p->configured = false; + p->plugin_state = UNCONFIGURED; p->js_arr = tal_arr(p, struct json_stream *, 0); p->used = 0; p->subscriptions = NULL; @@ -930,7 +930,7 @@ void plugins_start(struct plugins *plugins, const char *dev_plugin_debug) struct jsonrpc_request *req; list_for_each(&plugins->plugins, p, list) { - if (p->configured) + if (p->plugin_state != UNCONFIGURED) continue; bool debug; @@ -996,7 +996,7 @@ static void plugin_config_cb(const char *buffer, const jsmntok_t *idtok, struct plugin *plugin) { - plugin->configured = true; + plugin->plugin_state = CONFIGURED; } /* FIXME(cdecker) This just builds a string for the request because @@ -1037,8 +1037,10 @@ void plugins_config(struct plugins *plugins) { struct plugin *p; list_for_each(&plugins->plugins, p, list) { - if (!p->configured) + if (p->plugin_state == UNCONFIGURED) { + p->plugin_state = CONFIGURING; plugin_config(p); + } } } diff --git a/lightningd/plugin.h b/lightningd/plugin.h index 033ea5966..8787b6237 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -8,6 +8,12 @@ #include #include +enum plugin_state { + UNCONFIGURED, + CONFIGURING, + CONFIGURED +}; + /** * A plugin, exposed as a stub so we can pass it as an argument. */ @@ -20,7 +26,9 @@ struct plugin { bool stop; struct plugins *plugins; const char **plugin_path; - bool configured; + + enum plugin_state plugin_state; + /* If this plugin can be restarted without restarting lightningd */ bool dynamic; bool signal_startup; diff --git a/lightningd/plugin_control.c b/lightningd/plugin_control.c index 89393d557..ff5d49e78 100644 --- a/lightningd/plugin_control.c +++ b/lightningd/plugin_control.c @@ -107,7 +107,8 @@ static struct command_result *json_plugin_control(struct command *cmd, list_for_each(&cmd->ld->plugins->plugins, p, list) { json_object_start(response, NULL); json_add_string(response, "name", p->cmd); - json_add_bool(response, "active", p->configured); + json_add_bool(response, "active", + p->plugin_state == CONFIGURED); json_object_end(response); } json_array_end(response); diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 2d1aaacc3..4ad2e84ee 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -90,7 +90,6 @@ def test_plugin_dir(node_factory): node_factory.get_node(options={'plugin-dir': plugin_dir, 'greeting': 'Mars'}) -@pytest.mark.xfail(strict=True) def test_plugin_slowinit(node_factory): """Tests the 'plugin' RPC command when init is slow""" n = node_factory.get_node()