Browse Source

lightningd/plugin_control: don't control non-dynamic plugins

pull/2938/head
darosior 6 years ago
committed by Rusty Russell
parent
commit
307fb0708e
  1. 4
      lightningd/plugin_control.c
  2. 25
      tests/plugins/static.py
  3. 7
      tests/test_plugin.py

4
lightningd/plugin_control.c

@ -39,6 +39,10 @@ static struct command_result *json_plugin_control(struct command *cmd,
plugin_found = false;
list_for_each(&cmd->ld->plugins->plugins, p, list) {
if (plugin_paths_match(p->cmd, plugin_name)) {
if (!p->dynamic)
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"%s plugin cannot be managed when lightningd is up",
plugin_name);
plugin_found = true;
plugin_hook_unregister_all(p);
plugin_kill(p, "%s stopped by lightningd via RPC",

25
tests/plugins/static.py

@ -0,0 +1,25 @@
#!/usr/bin/env python3
"""Simple plugin to test the dynamic behavior.
A plugin started with dynamic to False cannot be controlled after lightningd
has been started.
"""
from lightning import Plugin
plugin = Plugin(dynamic=False)
@plugin.init()
def init(configuration, options, plugin):
plugin.log("Static plugin initialized.")
@plugin.method('hello')
def reject(plugin):
"""Mark a given node_id as reject for future connections.
"""
return "Hello, you cannot stop me without stopping lightningd"
plugin.run()

7
tests/test_plugin.py

@ -130,6 +130,13 @@ def test_plugin_command(node_factory):
cmd = [hlp for hlp in n.rpc.help()["help"] if "hello" in hlp["command"]]
assert(len(cmd) == 0)
# Test that we cannot stop a plugin with 'dynamic' set to False in
# getmanifest
n.rpc.plugin_start(plugin=os.path.join(os.getcwd(), "tests/plugins/static.py"))
n.daemon.wait_for_log(r"Static plugin initialized.")
with pytest.raises(RpcError, match=r"plugin cannot be managed when lightningd is up"):
n.rpc.plugin_stop(plugin="static.py")
def test_plugin_disable(node_factory):
"""--disable-plugin works"""

Loading…
Cancel
Save