plugins: return also on register error in add_plugin_dir()

This commit is contained in:
darosior
2019-09-10 17:46:08 +02:00
committed by Rusty Russell
parent fcc358c9bc
commit 6694dda8a3
2 changed files with 12 additions and 6 deletions

View File

@@ -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;