From 3a5211048d3bd12a09578c4bcfdbdd134196710e Mon Sep 17 00:00:00 2001 From: darosior Date: Sat, 14 Sep 2019 17:35:00 +0200 Subject: [PATCH] plugins: make 'plugin startdir' 's runtime path independant This does the same as for the 'start' subcommand for the 'startdir' one. Note that we could fail to start the last plugin of a directory, but have succesfully started the precedent plugins. This will make us return an error to the user while some of the plugins have been started, but we still don't end up in a transient state with half-configured-half-errored plugins. --- lightningd/plugin_control.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lightningd/plugin_control.c b/lightningd/plugin_control.c index 3abde0abc..aa3e0f789 100644 --- a/lightningd/plugin_control.c +++ b/lightningd/plugin_control.c @@ -163,6 +163,38 @@ plugin_dynamic_start(struct command *cmd, const char *plugin_path) return plugin_start(dp); } +/** + * Called when trying to start a plugin directory through RPC, it registers + * all contained plugins recursively and then starts them. + */ +static struct command_result * +plugin_dynamic_startdir(struct command *cmd, const char *dir_path) +{ + const char *err; + struct plugin *p; + /* If the directory is empty */ + bool found; + + err = add_plugin_dir(cmd->ld->plugins, dir_path, false); + if (err) + return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "%s", err); + + found = false; + list_for_each(&cmd->ld->plugins->plugins, p, list) { + if (p->plugin_state == UNCONFIGURED) { + found = true; + struct dynamic_plugin *dp = tal(cmd, struct dynamic_plugin); + dp->plugin = p; + dp->cmd = cmd; + plugin_start(dp); + } + } + if (!found) + plugin_dynamic_list_plugins(cmd); + + return command_still_pending(cmd); +} + /** * A plugin command which permits to control plugins without restarting * lightningd. It takes a subcommand, and an optional subcommand parameter. @@ -233,7 +265,7 @@ static struct command_result *json_plugin_control(struct command *cmd, return command_param_failed(); if (access(dir_path, F_OK) == 0) - add_plugin_dir(cmd->ld->plugins, dir_path, true); + return plugin_dynamic_startdir(cmd, dir_path); else return command_fail(cmd, JSONRPC2_INVALID_PARAMS, "Could not open %s", dir_path);