From fc3bad216090a47daa74619174afe8c542ac1de9 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 17 Jul 2022 22:08:05 +0200 Subject: [PATCH] Fix #284: search for plugins in /usr and /usr/local Signed-off-by: Joachim Wiberg --- configure.ac | 8 ++++++++ src/plugin.c | 26 ++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 19a0b5b2..3f38b832 100644 --- a/configure.ac +++ b/configure.ac @@ -151,6 +151,9 @@ AC_ARG_WITH(hook-scripts-path, AS_HELP_STRING([--with-hook-scripts-path=DIR], [Base directory for hook scripts, default $libexecdir/finit/hook]), [hook_scripts_path=$withval], [hook_scripts_path=yes]) +AC_ARG_WITH(plugin-path, + AS_HELP_STRING([--with-plugin-path=DIR], [Search path for external plugins, default /usr/lib/finit/plugins:/usr/local/lib/finit/plugins]), + [plugin_path=$withval], [plugin_path=yes]) ### Enable features ########################################################################### @@ -251,6 +254,11 @@ AS_IF([test "x$enable_hook_scripts_plugin" = "xyes" -a "x$with_hook_scripts_path AC_EXPAND_DIR(hook_scripts_path, "$hook_scripts_path") AC_DEFINE_UNQUOTED(PLUGIN_HOOK_SCRIPTS_PATH, "$hook_scripts_path", [Built-in default: $libexecdir/finit])]) +AS_IF([test "x$with_plugin_path" != "xno"], [ + AS_IF([test "x$plugin_path" = "xyes"], [plugin_path=/usr/lib/finit/plugins:/usr/local/lib/finit/plugins]) + AC_EXPAND_DIR(plugin_path, "$plugin_path") + AC_DEFINE_UNQUOTED(EXTERNAL_PLUGIN_PATH, "$plugin_path", [Built-in default: /usr/lib/finit/plugins:/usr/local/lib/finit/plugins])]) + # Control build with automake flags AM_CONDITIONAL(STATIC, [test "x$enable_static" = "xyes"]) AM_CONDITIONAL(KEVENTD, [test "x$with_keventd" != "xno"]) diff --git a/src/plugin.c b/src/plugin.c index 25bf2d34..d345624d 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -260,8 +260,8 @@ int plugin_io_init(plugin_t *p) /* Setup any I/O callbacks for plugins that use them */ static int init_plugins(uev_ctx_t *ctx) { - int fail = 0; plugin_t *p, *tmp; + int fail = 0; PLUGIN_ITERATOR(p, tmp) { if (plugin_io_init(p)) @@ -302,7 +302,7 @@ static int load_one(char *path, char *name) noext = strcmp(name + strlen(name) - 3, ".so"); snprintf(sofile, sizeof(sofile), "%s/%s%s", path, name, noext ? ".so" : ""); - _d("Loading plugin %s ...", basename(sofile)); + _d("Loading plugin %s ...", sofile); handle = dlopen(sofile, RTLD_LAZY | RTLD_LOCAL); if (!handle) { _e("Failed loading plugin %s: %s", sofile, dlerror()); @@ -356,6 +356,8 @@ static int load_plugins(char *path) dp = opendir(path); if (!dp) { + if (errno == ENOENT) + return 0; _e("Failed, cannot open plugin directory %s: %s", path, strerror(errno)); return 1; } @@ -383,12 +385,24 @@ static int load_plugins(char *path) int plugin_init(uev_ctx_t *ctx) { - int fail = 1; + load_plugins(PLUGIN_PATH); - if (!load_plugins(PLUGIN_PATH)) - fail = init_plugins(ctx); +#ifdef EXTERNAL_PLUGIN_PATH + char *paths = strdup(EXTERNAL_PLUGIN_PATH); + char *path; - return fail; + if (paths) { + _d("Loading external plugins from %s ...", paths); + path = strtok(paths, ":"); + while (path) { + load_plugins(path); + path = strtok(NULL, ":"); + } + free(paths); + } +#endif + + return init_plugins(ctx); } void plugin_exit(void)