From 5bdf349771e5be3694430ef0490619c2b6091ac8 Mon Sep 17 00:00:00 2001 From: darosior Date: Sun, 15 Sep 2019 22:41:19 +0200 Subject: [PATCH] plugins: make the default plugins directory a member of 'plugins' --- lightningd/plugin.c | 13 +++++++------ lightningd/plugin.h | 6 +++--- lightningd/plugin_control.c | 3 +-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index f47b82b62..22103ae21 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -943,18 +943,19 @@ void clear_plugins(struct plugins *plugins) tal_free(p); } -void plugins_add_default_dir(struct plugins *plugins, const char *default_dir) +void plugins_add_default_dir(struct plugins *plugins) { - DIR *d = opendir(default_dir); + DIR *d = opendir(plugins->default_dir); if (d) { struct dirent *di; /* Add this directory itself, and recurse down once. */ - add_plugin_dir(plugins, default_dir, true); + add_plugin_dir(plugins, plugins->default_dir, true); while ((di = readdir(d)) != NULL) { if (streq(di->d_name, ".") || streq(di->d_name, "..")) continue; - add_plugin_dir(plugins, path_join(tmpctx, default_dir, di->d_name), true); + add_plugin_dir(plugins, path_join(tmpctx, plugins->default_dir, + di->d_name), true); } closedir(d); } @@ -968,8 +969,8 @@ void plugins_init(struct plugins *plugins, const char *dev_plugin_debug) struct jsonrpc_request *req; plugins->pending_manifests = 0; - plugins_add_default_dir(plugins, - path_join(tmpctx, plugins->ld->config_dir, "plugins")); + plugins->default_dir = path_join(plugins, plugins->ld->config_dir, "plugins"); + plugins_add_default_dir(plugins); setenv("LIGHTNINGD_PLUGIN", "1", 1); setenv("LIGHTNINGD_VERSION", version(), 1); diff --git a/lightningd/plugin.h b/lightningd/plugin.h index a322204aa..1130790e2 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -84,6 +84,7 @@ struct plugins { struct log_book *log_book; struct lightningd *ld; + const char *default_dir; }; /* The value of a plugin option, which can have different types. @@ -115,10 +116,9 @@ struct plugins *plugins_new(const tal_t *ctx, struct log_book *log_book, struct lightningd *ld); /** - * Search for `default_dir`, and if it exists add every directory it - * contains as a plugin dir. + * Recursively add all plugins from the default plugins directory. */ -void plugins_add_default_dir(struct plugins *plugins, const char *default_dir); +void plugins_add_default_dir(struct plugins *plugins); /** * Initialize the registered plugins. diff --git a/lightningd/plugin_control.c b/lightningd/plugin_control.c index 970c49665..897ad99ac 100644 --- a/lightningd/plugin_control.c +++ b/lightningd/plugin_control.c @@ -223,8 +223,7 @@ plugin_dynamic_rescan_plugins(struct command *cmd) struct plugin *p; /* This will not fail on "already registered" error. */ - plugins_add_default_dir(cmd->ld->plugins, - path_join(tmpctx, cmd->ld->config_dir, "plugins")); + plugins_add_default_dir(cmd->ld->plugins); found = false; list_for_each(&cmd->ld->plugins->plugins, p, list) {