From 41409be407ea9889ac013ea7c599387d50022fd4 Mon Sep 17 00:00:00 2001 From: Brian Barto Date: Thu, 21 Apr 2022 14:50:24 -0400 Subject: [PATCH 1/2] When starting a plugin, if the plugin path cannot be found in absolute context, assume it is a relative path to the default plugins dir. As a result, the following now works when my_plugin.py is installed in the default plugins dir: lightning-cli plugin start my_plugin.py Changelog-Added: plugin start RPC subcommand now assumes relative path to default plugins dir if the path is not found in absolute context. i.e. lightning-cli plugin start my_plugin.py modified: plugin_control.c --- lightningd/plugin_control.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lightningd/plugin_control.c b/lightningd/plugin_control.c index b583ef1a148e..aa503a7cb9b0 100644 --- a/lightningd/plugin_control.c +++ b/lightningd/plugin_control.c @@ -1,4 +1,5 @@ #include "config.h" +#include #include #include #include @@ -256,6 +257,10 @@ static struct command_result *json_plugin_control(struct command *cmd, json_get_member(buffer, mod_params, "plugin") - 1, 1); } + if (access(plugin_path, X_OK) != 0) + plugin_path = path_join(cmd, + path_join(cmd, cmd->ld->config_basedir, "plugins/"), + plugin_path); if (access(plugin_path, X_OK) == 0) return plugin_dynamic_start(pcmd, plugin_path, buffer, mod_params); From 2181627377ecc310ef026f201ec4968d246c79ee Mon Sep 17 00:00:00 2001 From: Brian Barto Date: Wed, 18 May 2022 15:18:35 -0400 Subject: [PATCH 2/2] lightning-cli plugin start - Use cmd->ld->plugins->default_dir In relative path context, use the default plugin path available at cmd->ld->plugins->default_dir instead of piecing it together using the lightning basedir and "plugins/". Also update the plugin documentation to reflect that the use of a relative path is now available. Changelog-Added: plugin start RPC subcommand now derives the default plugin dir available via cmd->ld->plugins->default_dir to search for plugins in relative path context. Plugin documentation also updated. modified: doc/lightning-plugin.7.md modified: lightningd/plugin_control.c --- doc/lightning-plugin.7.md | 8 +++++--- lightningd/plugin_control.c | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/lightning-plugin.7.md b/doc/lightning-plugin.7.md index 7c3032075a54..dd9b765d4ca7 100644 --- a/doc/lightning-plugin.7.md +++ b/doc/lightning-plugin.7.md @@ -16,9 +16,11 @@ optionally one or two parameters which describes the plugin on which the action has to be taken. The *start* command takes a path as the first parameter and will load -the plugin available from this path. Any additional parameters are -passed to the plugin. It will wait for the plugin to complete the -handshake with `lightningd` for 20 seconds at the most. +the plugin available from this path. The path can be a full path to a +plugin or a relative path to a plugin that is located in or below the +default plugins directory. Any additional parameters are passed to the +plugin. It will wait for the plugin to complete the handshake with +`lightningd` for 20 seconds at the most. The *stop* command takes a plugin name as parameter. It will kill and unload the specified plugin. diff --git a/lightningd/plugin_control.c b/lightningd/plugin_control.c index aa503a7cb9b0..bee3ef56c3a4 100644 --- a/lightningd/plugin_control.c +++ b/lightningd/plugin_control.c @@ -259,8 +259,7 @@ static struct command_result *json_plugin_control(struct command *cmd, } if (access(plugin_path, X_OK) != 0) plugin_path = path_join(cmd, - path_join(cmd, cmd->ld->config_basedir, "plugins/"), - plugin_path); + cmd->ld->plugins->default_dir, plugin_path); if (access(plugin_path, X_OK) == 0) return plugin_dynamic_start(pcmd, plugin_path, buffer, mod_params);