plugin: Remove added JSON-RPC methods if a plugin gets killed

Removes the method from the dispatch table, leaving a NULL entry
currently.

Signed-off-by: Christian Decker <@cdecker>
This commit is contained in:
Christian Decker
2018-11-22 23:11:26 +01:00
committed by Rusty Russell
parent 7de4c40b77
commit a71208b2a0
4 changed files with 34 additions and 8 deletions

View File

@@ -118,6 +118,8 @@ static void plugin_kill(struct plugin *plugin, char *msg)
plugin->stop = true;
io_wake(plugin);
kill(plugin->pid, SIGKILL);
list_del(&plugin->list);
tal_free(plugin);
}
/**
@@ -384,8 +386,10 @@ static bool plugin_opts_add(const struct plugin_request *req)
return true;
}
static void plugin_rpcmethod_destroy(struct json_command *cmd)
static void plugin_rpcmethod_destroy(struct json_command *cmd,
struct jsonrpc *rpc)
{
jsonrpc_command_remove(rpc, cmd->name);
}
static void plugin_rpcmethod_dispatch(struct command *cmd, const char *buffer,
@@ -448,7 +452,7 @@ static bool plugin_rpcmethod_add(struct plugin *plugin, const char *buffer,
cmd->deprecated = false;
cmd->dispatch = plugin_rpcmethod_dispatch;
tal_add_destructor(cmd, plugin_rpcmethod_destroy);
tal_add_destructor2(cmd, plugin_rpcmethod_destroy, plugin->plugins->rpc);
if (!jsonrpc_command_add(plugin->plugins->rpc, cmd)) {
log_broken(plugin->log,
"Could not register method \"%s\", a method with "