plugins: allow plugins to disable themselves at startup.

By returning 'disable: <reason>' inside getmanifest or init result.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: plugins: plugins can now disable themselves by returning `disable`, even if marked important.
This commit is contained in:
Rusty Russell
2021-01-13 13:30:24 +10:30
committed by Christian Decker
parent fc3e679c97
commit 529ae0d766
5 changed files with 104 additions and 7 deletions

View File

@@ -1,10 +1,15 @@
PLUGIN_TESTLIBPLUGIN_SRC := tests/plugins/test_libplugin.c
PLUGIN_TESTLIBPLUGIN_SRC := tests/plugins/test_libplugin.c
PLUGIN_TESTLIBPLUGIN_OBJS := $(PLUGIN_TESTLIBPLUGIN_SRC:.c=.o)
tests/plugins/test_libplugin: bitcoin/chainparams.o $(PLUGIN_TESTLIBPLUGIN_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
$(PLUGIN_TESTLIBPLUGIN_OBJS): $(PLUGIN_LIB_HEADER)
PLUGIN_TESTSELFDISABLE_AFTER_GETMANIFEST_SRC := tests/plugins/test_selfdisable_after_getmanifest.c
PLUGIN_TESTSELFDISABLE_AFTER_GETMANIFEST_OBJS := $(PLUGIN_TESTSELFDISABLE_AFTER_GETMANIFEST_SRC:.c=.o)
tests/plugins/test_selfdisable_after_getmanifest: bitcoin/chainparams.o $(PLUGIN_TESTSELFDISABLE_AFTER_GETMANIFEST_OBJS) common/json.o common/json_stream.o common/setup.o common/utils.o $(JSMN_OBJS) $(CCAN_OBJS)
# Make sure these depend on everything.
ALL_TEST_PROGRAMS += tests/plugins/test_libplugin
ALL_C_SOURCES += $(PLUGIN_TESTLIBPLUGIN_SRC)
ALL_TEST_PROGRAMS += tests/plugins/test_libplugin tests/plugins/test_selfdisable_after_getmanifest
ALL_C_SOURCES += $(PLUGIN_TESTLIBPLUGIN_SRC) $(PLUGIN_TESTSELFDISABLE_AFTER_GETMANIFEST_SRC)

View File

@@ -0,0 +1,42 @@
#include <ccan/err/err.h>
#include <ccan/read_write_all/read_write_all.h>
#include <ccan/tal/tal.h>
#include <ccan/tal/str/str.h>
#include <common/json.h>
#include <common/setup.h>
#include <common/utils.h>
#include <unistd.h>
/* Our normal frameworks don't (yet?) support custom post-manifest responses,
* so this is open-coded */
int main(int argc, char *argv[])
{
char *buf;
int r, off;
const jsmntok_t *toks, *id;
common_setup(argv[0]);
buf = tal_arr(tmpctx, char, 100);
off = 0;
do {
r = read(STDIN_FILENO, buf + off, tal_bytelen(buf) - off);
if (r < 0)
err(1, "reading stdin");
off += r;
if (off == tal_bytelen(buf))
tal_resize(&buf, off * 2);
toks = json_parse_simple(tmpctx, buf, off);
} while (!toks);
/* Tell it we're disabled (reusing id). */
id = json_get_member(buf, toks, "id");
buf = tal_fmt(tmpctx, "{\"jsonrpc\":\"2.0\",\"id\":%.*s,\"result\":{\"disable\":\"Self-disable test after getmanifest\"} }",
json_tok_full_len(id),
json_tok_full(buf, id));
write_all(STDOUT_FILENO, buf, strlen(buf));
common_shutdown();
return 0;
}