lightning-cli plugin start - Assume default relative path

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

Also update the plugin documentation to reflect that the use of a
relative path is now available.

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

[ Squashed two commits into one -- RR ]
This commit is contained in:
Brian Barto
2022-06-17 00:48:48 -04:00
committed by GitHub
parent 0c9017fb76
commit 24b02c33cc
2 changed files with 9 additions and 3 deletions

View File

@@ -16,9 +16,11 @@ optionally one or two parameters which describes the plugin on which the
action has to be taken. action has to be taken.
The *start* command takes a path as the first parameter and will load The *start* command takes a path as the first parameter and will load
the plugin available from this path. Any additional parameters are the plugin available from this path. The path can be a full path to a
passed to the plugin. It will wait for the plugin to complete the plugin or a relative path to a plugin that is located in or below the
handshake with `lightningd` for 20 seconds at the most. 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 The *stop* command takes a plugin name as parameter. It will kill and
unload the specified plugin. unload the specified plugin.

View File

@@ -1,4 +1,5 @@
#include "config.h" #include "config.h"
#include <ccan/tal/path/path.h>
#include <ccan/tal/str/str.h> #include <ccan/tal/str/str.h>
#include <common/json_command.h> #include <common/json_command.h>
#include <common/json_tok.h> #include <common/json_tok.h>
@@ -256,6 +257,9 @@ static struct command_result *json_plugin_control(struct command *cmd,
json_get_member(buffer, mod_params, json_get_member(buffer, mod_params,
"plugin") - 1, 1); "plugin") - 1, 1);
} }
if (access(plugin_path, X_OK) != 0)
plugin_path = path_join(cmd,
cmd->ld->plugins->default_dir, plugin_path);
if (access(plugin_path, X_OK) == 0) if (access(plugin_path, X_OK) == 0)
return plugin_dynamic_start(pcmd, plugin_path, return plugin_dynamic_start(pcmd, plugin_path,
buffer, mod_params); buffer, mod_params);