Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libplugin: use json stream helpers and add sanity tests #3480

Merged
merged 10 commits into from
Feb 9, 2020
2 changes: 1 addition & 1 deletion lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ static bool plugin_opt_add(struct plugin *plugin, const char *buffer,
popt = tal(plugin, struct plugin_opt);
popt->value = talz(popt, struct plugin_opt_value);

popt->name = tal_fmt(plugin, "--%.*s", nametok->end - nametok->start,
popt->name = tal_fmt(popt, "--%.*s", nametok->end - nametok->start,
buffer + nametok->start);
if (json_tok_streq(buffer, typetok, "string")) {
popt->type = "string";
Expand Down
17 changes: 14 additions & 3 deletions lightningd/plugin_control.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <ccan/opt/opt.h>
#include <lightningd/options.h>
#include <lightningd/plugin_control.h>
#include <lightningd/plugin_hook.h>
Expand Down Expand Up @@ -196,6 +197,18 @@ plugin_dynamic_startdir(struct command *cmd, const char *dir_path)
return command_still_pending(cmd);
}

static void clear_plugin(struct plugin *p, const char *name)
{
struct plugin_opt *opt;

list_for_each(&p->plugin_opts, opt, list)
if (!opt_unregister(opt->name))
fatal("Could not unregister %s from plugin %s",
opt->name, name);
plugin_kill(p, "%s stopped by lightningd via RPC", name);
tal_free(p);
}

static struct command_result *
plugin_dynamic_stop(struct command *cmd, const char *plugin_name)
{
Expand All @@ -209,9 +222,7 @@ plugin_dynamic_stop(struct command *cmd, const char *plugin_name)
"%s cannot be managed when "
"lightningd is up",
plugin_name);
plugin_hook_unregister_all(p);
plugin_kill(p, "%s stopped by lightningd via RPC", plugin_name);
tal_free(p);
clear_plugin(p, plugin_name);
response = json_stream_success(cmd);
if (deprecated_apis)
json_add_string(response, "",
Expand Down
1 change: 1 addition & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ def test_rpc_command_hook(node_factory):
l1.rpc.plugin_stop('rpc_command.py')


@flaky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this now @flaky?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it started failing randomly on Travis but I was not able to reproduce locally..

Btw, i can no longer restart Travis jobs.. Don't know if it's a perm error or anything

def test_libplugin(node_factory):
"""Sanity checks for plugins made with libplugin"""
plugin = os.path.join(os.getcwd(), "tests/plugins/test_libplugin")
Expand Down