plugin: notice when plugin has *started* configuring.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2019-07-29 17:00:51 +09:30 committed by ZmnSCPxj, ZmnSCPxj jxPCSmnZ
parent df8a6f615b
commit 79d32ec2f2
4 changed files with 17 additions and 7 deletions

View File

@ -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);
}
}
}

View File

@ -8,6 +8,12 @@
#include <lightningd/jsonrpc.h>
#include <lightningd/log.h>
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;

View File

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

View File

@ -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()