lightningd/plugin.c: Make builtin plugins important.

Changelog-Changed: plugin: Builtin plugins are now marked as important, and if they crash, will cause C-lightning to stop as well.
This commit is contained in:
ZmnSCPxj jxPCSnmZ 2020-07-30 14:04:59 +08:00 committed by neil saitug
parent 48f36904c8
commit 4ca2e49812
6 changed files with 29 additions and 8 deletions

View File

@ -268,6 +268,15 @@ include tools/Makefile
include plugins/Makefile
include tests/plugins/Makefile
# Generated from PLUGINS definition in plugins/Makefile
gen_list_of_builtin_plugins.h : plugins/Makefile Makefile
@echo GEN $@
@rm -f $@ || true
@echo 'static const char *list_of_builtin_plugins[] = {' >> $@
@echo '$(PLUGINS)' | sed 's@plugins/\([^ ]*\)@"\1",@g'>> $@
@echo 'NULL' >> $@
@echo '};' >> $@
# Git doesn't maintain timestamps, so we only regen if git says we should.
CHANGED_FROM_GIT = [ x"`git log $@ | head -n1`" != x"`git log $< | head -n1`" -o x"`git diff $<`" != x"" ]

View File

@ -557,6 +557,8 @@ plugin stops for any reason (including via \fBlightning-plugin\fR(7) \fBstop\fR)
C-lightning will also stop running\.
This way, you can monitor crashes of important plugins by simply monitoring
if C-lightning terminates\.
Built-in plugins, which are installed with \fBlightningd\fR(8), are automatically
considered important\.
.SH BUGS

View File

@ -460,6 +460,8 @@ plugin stops for any reason (including via lightning-plugin(7) `stop`),
C-lightning will also stop running.
This way, you can monitor crashes of important plugins by simply monitoring
if C-lightning terminates.
Built-in plugins, which are installed with lightningd(8), are automatically
considered important.
BUGS
----

View File

@ -137,6 +137,9 @@ LIGHTNINGD_HEADERS = $(LIGHTNINGD_HEADERS_NOGEN) $(LIGHTNINGD_HEADERS_GEN) $(WAL
$(LIGHTNINGD_OBJS): $(LIGHTNINGD_HEADERS)
# Only the plugin component needs to depend on this header.
lightningd/plugin.o : gen_list_of_builtin_plugins.h
lightningd/gen_channel_state_names.h: lightningd/channel_state.h ccan/ccan/cdump/tools/cdump-enumstr
ccan/ccan/cdump/tools/cdump-enumstr lightningd/channel_state.h > $@

View File

@ -16,6 +16,9 @@
#include <sys/stat.h>
#include <sys/types.h>
/* Only this file can include this generated header! */
# include <gen_list_of_builtin_plugins.h>
/* How many seconds may the plugin take to reply to the `getmanifest`
* call? This is the maximum delay to `lightningd --help` and until
* we can start the main `io_loop` to communicate with peers. If this
@ -1582,11 +1585,13 @@ struct log *plugin_get_log(struct plugin *plugin)
void plugins_set_builtin_plugins_dir(struct plugins *plugins,
const char *dir)
{
/*~ The builtin-plugins dir does not need to exist, but
* we would error those anyway for our important built-in
* plugins.
*/
add_plugin_dir(plugins, dir, true);
/*~ Load the builtin plugins as important. */
for (size_t i = 0; list_of_builtin_plugins[i]; ++i)
plugin_register(plugins,
take(path_join(NULL, dir,
list_of_builtin_plugins[i])),
NULL,
/* important = */ true);
}
struct plugin_destroyed {

View File

@ -844,9 +844,9 @@ def test_listconfigs_plugins(node_factory, bitcoind, chainparams):
# assert that we have pay plugin and that plugins have a name and path
configs = l1.rpc.listconfigs()
assert configs['plugins']
assert len([p for p in configs['plugins'] if p['name'] == "pay"]) == 1
for p in configs['plugins']:
assert configs['important-plugins']
assert len([p for p in configs['important-plugins'] if p['name'] == "pay"]) == 1
for p in configs['important-plugins']:
assert p['name'] and len(p['name']) > 0
assert p['path'] and len(p['path']) > 0
assert os.path.isfile(p['path']) and os.access(p['path'], os.X_OK)