diff --git a/lightningd/plugin.c b/lightningd/plugin.c index 1c075b2af..9783fba41 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -901,10 +901,12 @@ static const char *plugin_fullpath(const tal_t *ctx, const char *dir, return fullname; } -char *add_plugin_dir(struct plugins *plugins, const char *dir, bool nonexist_ok) +char *add_plugin_dir(struct plugins *plugins, const char *dir, bool error_ok) { struct dirent *di; DIR *d = opendir(dir); + struct plugin *p; + if (!d) { if (deprecated_apis && !path_is_abs(dir)) { dir = path_join(tmpctx, @@ -919,7 +921,7 @@ char *add_plugin_dir(struct plugins *plugins, const char *dir, bool nonexist_ok) } } if (!d) { - if (!nonexist_ok && errno == ENOENT) + if (!error_ok && errno == ENOENT) return NULL; return tal_fmt(NULL, "Failed to open plugin-dir %s: %s", dir, strerror(errno)); @@ -931,9 +933,13 @@ char *add_plugin_dir(struct plugins *plugins, const char *dir, bool nonexist_ok) if (streq(di->d_name, ".") || streq(di->d_name, "..")) continue; - fullpath = plugin_fullpath(NULL, dir, di->d_name); - if (fullpath) - plugin_register(plugins, take(fullpath)); + fullpath = plugin_fullpath(tmpctx, dir, di->d_name); + if (fullpath) { + p = plugin_register(plugins, fullpath); + if (!p && !error_ok) + return tal_fmt(NULL, "Failed to register %s: %s", + fullpath, strerror(errno)); + } } closedir(d); return NULL; diff --git a/lightningd/plugin.h b/lightningd/plugin.h index 11c499acc..f61502630 100644 --- a/lightningd/plugin.h +++ b/lightningd/plugin.h @@ -181,7 +181,7 @@ void *plugin_exclusive_loop(struct plugin *plugin); * Add a directory to the plugin path to automatically load plugins. */ char *add_plugin_dir(struct plugins *plugins, const char *dir, - bool nonexist_ok); + bool error_ok); /** * Clear all plugins registered so far.