Browse Source

libplugin: fix 'dynamic' field in getmanifest

As a separated commit because it was pre-existent (changelog + xfail test).

This also fix a logical problem in lightningd/plugin_control: we were
assuming a plugin started with 'plugin start' but which did not comport
a 'dynamic' entry in its manifest to be dynamic, though it should have
been treated as static.

Changelog-fixed: plugins: Dynamic C plugins can now be managed when lightningd is up
travis-debug
darosior 5 years ago
committed by Rusty Russell
parent
commit
ceeb5503cc
  1. 9
      lightningd/plugin.c
  2. 2
      lightningd/plugin_control.c
  3. 3
      plugins/libplugin.c
  4. 1
      tests/test_plugin.py

9
lightningd/plugin.c

@ -73,6 +73,7 @@ struct plugin *plugin_register(struct plugins *plugins, const char* path TAKES)
p->js_arr = tal_arr(p, struct json_stream *, 0); p->js_arr = tal_arr(p, struct json_stream *, 0);
p->used = 0; p->used = 0;
p->subscriptions = NULL; p->subscriptions = NULL;
p->dynamic = false;
p->log = new_log(p, plugins->log_book, NULL, "plugin-%s", p->log = new_log(p, plugins->log_book, NULL, "plugin-%s",
path_basename(tmpctx, p->cmd)); path_basename(tmpctx, p->cmd));
@ -810,22 +811,22 @@ static void plugin_manifest_timeout(struct plugin *plugin)
fatal("Can't recover from plugin failure, terminating."); fatal("Can't recover from plugin failure, terminating.");
} }
bool plugin_parse_getmanifest_response(const char *buffer, bool plugin_parse_getmanifest_response(const char *buffer,
const jsmntok_t *toks, const jsmntok_t *toks,
const jsmntok_t *idtok, const jsmntok_t *idtok,
struct plugin *plugin) struct plugin *plugin)
{ {
const jsmntok_t *resulttok, *dynamictok; const jsmntok_t *resulttok, *dynamictok;
bool dynamic_plugin;
resulttok = json_get_member(buffer, toks, "result"); resulttok = json_get_member(buffer, toks, "result");
if (!resulttok || resulttok->type != JSMN_OBJECT) if (!resulttok || resulttok->type != JSMN_OBJECT)
return false; return false;
dynamictok = json_get_member(buffer, resulttok, "dynamic"); dynamictok = json_get_member(buffer, resulttok, "dynamic");
if (dynamictok && json_to_bool(buffer, dynamictok, &dynamic_plugin)) if (dynamictok && !json_to_bool(buffer, dynamictok, &plugin->dynamic))
plugin->dynamic = dynamic_plugin; plugin_kill(plugin, "Bad 'dynamic' field ('%.*s')",
json_tok_full_len(dynamictok),
json_tok_full(buffer, dynamictok));
if (!plugin_opts_add(plugin, buffer, resulttok) || if (!plugin_opts_add(plugin, buffer, resulttok) ||
!plugin_rpcmethods_add(plugin, buffer, resulttok) || !plugin_rpcmethods_add(plugin, buffer, resulttok) ||

2
lightningd/plugin_control.c

@ -115,7 +115,7 @@ static struct command_result *plugin_start(struct dynamic_plugin *dp)
struct jsonrpc_request *req; struct jsonrpc_request *req;
struct plugin *p = dp->plugin; struct plugin *p = dp->plugin;
p->dynamic = true; p->dynamic = false;
p_cmd = tal_arrz(NULL, char *, 2); p_cmd = tal_arrz(NULL, char *, 2);
p_cmd[0] = p->cmd; p_cmd[0] = p->cmd;
/* In case the plugin create files, this is a better default. */ /* In case the plugin create files, this is a better default. */

3
plugins/libplugin.c

@ -591,8 +591,7 @@ handle_getmanifest(struct command *getmanifest_cmd)
json_add_string(params, NULL, p->hook_subs[i].name); json_add_string(params, NULL, p->hook_subs[i].name);
json_array_end(params); json_array_end(params);
json_add_string(params, "dynamic", json_add_bool(params, "dynamic", p->restartability == PLUGIN_RESTARTABLE);
p->restartability == PLUGIN_RESTARTABLE ? "true" : "false");
return command_finished(getmanifest_cmd, params); return command_finished(getmanifest_cmd, params);
} }

1
tests/test_plugin.py

@ -791,7 +791,6 @@ def test_rpc_command_hook(node_factory):
l1.rpc.plugin_stop('rpc_command.py') l1.rpc.plugin_stop('rpc_command.py')
@pytest.mark.xfail(strict=True)
def test_libplugin(node_factory): def test_libplugin(node_factory):
"""Sanity checks for plugins made with libplugin""" """Sanity checks for plugins made with libplugin"""
plugin = os.path.join(os.getcwd(), "tests/plugins/test_libplugin") plugin = os.path.join(os.getcwd(), "tests/plugins/test_libplugin")

Loading…
Cancel
Save