mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
plugins: make use of dynamic_plugin_list() in 'plugin list'
And make a function for the 'rescan' subcommand so that we are consistent and have only subcommand logic in the main function, which return command_still_pending() in any case (but 'stop'). patched-by: @rustyrussell
This commit is contained in:
parent
b9e40d4cc7
commit
7f181edebb
@ -223,6 +223,35 @@ plugin_dynamic_stop(struct command *cmd, const char *plugin_name)
|
|||||||
"Could not find plugin %s", plugin_name);
|
"Could not find plugin %s", plugin_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Look for additions in the default plugin directory.
|
||||||
|
*/
|
||||||
|
static struct command_result *
|
||||||
|
plugin_dynamic_rescan_plugins(struct command *cmd)
|
||||||
|
{
|
||||||
|
bool found;
|
||||||
|
struct plugin *p;
|
||||||
|
|
||||||
|
/* This will not fail on "already registered" error. */
|
||||||
|
plugins_add_default_dir(cmd->ld->plugins,
|
||||||
|
path_join(tmpctx, cmd->ld->config_dir, "plugins"));
|
||||||
|
|
||||||
|
found = false;
|
||||||
|
list_for_each(&cmd->ld->plugins->plugins, p, list) {
|
||||||
|
if (p->plugin_state == UNCONFIGURED) {
|
||||||
|
struct dynamic_plugin *dp = tal(cmd, struct dynamic_plugin);
|
||||||
|
dp->plugin = p;
|
||||||
|
dp->cmd = cmd;
|
||||||
|
plugin_start(dp);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
return plugin_dynamic_list_plugins(cmd);
|
||||||
|
return command_still_pending(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A plugin command which permits to control plugins without restarting
|
* A plugin command which permits to control plugins without restarting
|
||||||
* lightningd. It takes a subcommand, and an optional subcommand parameter.
|
* lightningd. It takes a subcommand, and an optional subcommand parameter.
|
||||||
@ -234,13 +263,11 @@ static struct command_result *json_plugin_control(struct command *cmd,
|
|||||||
{
|
{
|
||||||
const char *subcmd;
|
const char *subcmd;
|
||||||
subcmd = param_subcommand(cmd, buffer, params,
|
subcmd = param_subcommand(cmd, buffer, params,
|
||||||
"start", "stop", "startdir", "rescan", "list", NULL);
|
"start", "stop", "startdir",
|
||||||
|
"rescan", "list", NULL);
|
||||||
if (!subcmd)
|
if (!subcmd)
|
||||||
return command_param_failed();
|
return command_param_failed();
|
||||||
|
|
||||||
struct plugin *p;
|
|
||||||
struct json_stream *response;
|
|
||||||
|
|
||||||
if (streq(subcmd, "stop")) {
|
if (streq(subcmd, "stop")) {
|
||||||
const char *plugin_name;
|
const char *plugin_name;
|
||||||
|
|
||||||
@ -286,28 +313,18 @@ static struct command_result *json_plugin_control(struct command *cmd,
|
|||||||
NULL))
|
NULL))
|
||||||
return command_param_failed();
|
return command_param_failed();
|
||||||
|
|
||||||
plugins_add_default_dir(cmd->ld->plugins,
|
return plugin_dynamic_rescan_plugins(cmd);
|
||||||
path_join(tmpctx, cmd->ld->config_dir, "plugins"));
|
|
||||||
} else if (streq(subcmd, "list")) {
|
} else if (streq(subcmd, "list")) {
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req("subcommand", param_ignore, cmd),
|
p_req("subcommand", param_ignore, cmd),
|
||||||
NULL))
|
NULL))
|
||||||
return command_param_failed();
|
return command_param_failed();
|
||||||
/* Don't do anything as we return the plugin list anyway */
|
|
||||||
|
return plugin_dynamic_list_plugins(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
response = json_stream_success(cmd);
|
/* subcmd must be one of the above: param_subcommand checked it! */
|
||||||
json_array_start(response, "plugins");
|
abort();
|
||||||
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->plugin_state == CONFIGURED);
|
|
||||||
json_object_end(response);
|
|
||||||
}
|
|
||||||
json_array_end(response);
|
|
||||||
|
|
||||||
return command_success(cmd, response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct json_command plugin_control_command = {
|
static const struct json_command plugin_control_command = {
|
||||||
|
Loading…
Reference in New Issue
Block a user