Browse Source

plugins: return also on register error in add_plugin_dir()

travis-debug
darosior 6 years ago
committed by Rusty Russell
parent
commit
6694dda8a3
  1. 16
      lightningd/plugin.c
  2. 2
      lightningd/plugin.h

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

2
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.

Loading…
Cancel
Save