diff --git a/Makefile b/Makefile index fed668a80..a396fbf5f 100644 --- a/Makefile +++ b/Makefile @@ -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"" ] diff --git a/doc/lightningd-config.5 b/doc/lightningd-config.5 index 5f2a6d58b..6cc8ee1c9 100644 --- a/doc/lightningd-config.5 +++ b/doc/lightningd-config.5 @@ -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 diff --git a/doc/lightningd-config.5.md b/doc/lightningd-config.5.md index 316a7ac15..e71d9bb71 100644 --- a/doc/lightningd-config.5.md +++ b/doc/lightningd-config.5.md @@ -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 ---- diff --git a/lightningd/Makefile b/lightningd/Makefile index 77aa6438c..689c08053 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -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 > $@ diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 5fc4f6454..028ce8eb6 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -16,6 +16,9 @@ #include #include +/* Only this file can include this generated header! */ +# include + /* 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 { diff --git a/tests/test_misc.py b/tests/test_misc.py index 162353d0b..7e50d40bf 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -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)