- asprintf (&pluginPath, "%s/%s", session->config->plugins, pluginDir->d_name);
- plugin = dlopen (pluginPath, RTLD_NOW | RTLD_LOCAL);
- pluginRegisterFct = dlsym (plugin, "pluginRegister");
- free (pluginPath);
- if (!plugin) {
- if (verbose) fprintf(stderr, "[%s] is not a binary plugin, continuing...\n", pluginDir->d_name);
- continue;
- } else if (!pluginRegisterFct) {
- if (verbose) fprintf(stderr, "[%s] is not an AFB plugin, continuing...\n", pluginDir->d_name);
- continue;
+ // This is a loadable library let's check if it's a plugin
+ snprintf (pluginPath, sizeof(pluginPath), "%s/%s", dirpath, pluginDir.d_name);
+ libso = dlopen (pluginPath, RTLD_NOW | RTLD_LOCAL);
+
+ // Load fail we ignore this .so file
+ if (!libso) {
+ fprintf(stderr, "[%s] is not loadable, continuing...\n", pluginDir.d_name);
+ continue;
+ }
+
+ pluginRegisterFct = dlsym (libso, "pluginRegister");
+
+ if (!pluginRegisterFct) {
+ fprintf(stderr, "[%s] is not an AFB plugin, continuing...\n", pluginDir.d_name);
+ continue;
+ }
+
+ // if max plugin is reached let's stop searching
+ if (*count == AFB_MAX_PLUGINS) {
+ fprintf(stderr, "[%s] is not loaded [Max Count=%d reached]\n", pluginDir.d_name, *count);
+ continue;
+ }
+
+ if (verbose) fprintf(stderr, "[%s] is a valid AFB plugin, loading pos[%d]\n", pluginDir.d_name, *count);
+ plugins[*count] = pluginRegisterFct();
+ if (!plugins[*count]) {
+ if (verbose) fprintf(stderr, "ERROR: plugin [%s] register function failed. continuing...\n", pluginDir.d_name);
+ } else
+ *count = *count +1;