From: Kern Sibbald Date: Mon, 8 Mar 2010 12:53:37 +0000 (+0100) Subject: Fix plugin load not to stop if one plugin bad -- pointed out by James X-Git-Tag: Release-7.0.0~2086 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=72898a72c8025d19c93a2d5121c090c59940faf6;p=bacula%2Fbacula Fix plugin load not to stop if one plugin bad -- pointed out by James --- diff --git a/bacula/src/lib/plugins.c b/bacula/src/lib/plugins.c index bbe585f4fc..a0af158525 100644 --- a/bacula/src/lib/plugins.c +++ b/bacula/src/lib/plugins.c @@ -66,6 +66,22 @@ Plugin *new_plugin() return plugin; } +static void close_plugin(Plugin *plugin) +{ + if (plugin->file) { + Dmsg1(50, "Got plugin=%s but not accepted.\n", plugin->file); + } + if (plugin->unloadPlugin) { + plugin->unloadPlugin(); + } + if (plugin->pHandle) { + dlclose(plugin->pHandle); + } + if (plugin->file) { + free(plugin->file); + } + free(plugin); +} /* * Load all the plugins in the specified directory. @@ -143,7 +159,8 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, fname.c_str(), NPRT(dlerror())); Dmsg2(dbglvl, "Plugin load %s failed: ERR=%s\n", fname.c_str(), NPRT(dlerror())); - goto get_out; + close_plugin(plugin); + continue; } /* Get two global entry points */ @@ -153,7 +170,8 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, fname.c_str(), NPRT(dlerror())); Dmsg2(dbglvl, "Lookup of loadPlugin in plugin %s failed: ERR=%s\n", fname.c_str(), NPRT(dlerror())); - goto get_out; + close_plugin(plugin); + continue; } plugin->unloadPlugin = (t_unloadPlugin)dlsym(plugin->pHandle, "unloadPlugin"); if (!plugin->unloadPlugin) { @@ -161,17 +179,20 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, fname.c_str(), NPRT(dlerror())); Dmsg2(dbglvl, "Lookup of unloadPlugin in plugin %s failed: ERR=%s\n", fname.c_str(), NPRT(dlerror())); - goto get_out; + close_plugin(plugin); + continue; } /* Initialize the plugin */ if (loadPlugin(binfo, bfuncs, &plugin->pinfo, &plugin->pfuncs) != bRC_OK) { - goto get_out; + close_plugin(plugin); + continue; } if (!is_plugin_compatible) { Dmsg0(50, "Plugin compatibility pointer not set.\n"); } else if (!is_plugin_compatible(plugin)) { - goto get_out; + close_plugin(plugin); + continue; } found = true; /* found a plugin */ @@ -180,19 +201,7 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, get_out: if (!found && plugin) { - if (plugin->file) { - Dmsg1(50, "Got plugin=%s but not accepted.\n", plugin->file); - } - if (plugin->unloadPlugin) { - plugin->unloadPlugin(); - } - if (plugin->pHandle) { - dlclose(plugin->pHandle); - } - if (plugin->file) { - free(plugin->file); - } - free(plugin); + close_plugin(plugin); } if (entry) { free(entry);