]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/plugins.c
First cut of bat rerun a Job from Jobs Run
[bacula/bacula] / bacula / src / lib / plugins.c
index 26028534d54b25ece578304c2ed62f8d4644d026..de0819dd7a411811d6e991e5e379ba05b5439b7b 100644 (file)
@@ -6,7 +6,7 @@
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation, which is 
    listed in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -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.
@@ -105,6 +121,8 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir,
    }
    entry = (struct dirent *)malloc(sizeof(struct dirent) + name_max + 1000);
    for ( ;; ) {
+      plugin = NULL;            /* Start from a fresh plugin */
+
       if ((readdir_r(dp, entry, &result) != 0) || (result == NULL)) {
          if (!found) {
             Jmsg(NULL, M_WARNING, 0, _("Failed to find any plugins in %s\n"), 
@@ -143,7 +161,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 +172,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 +181,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 +203,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);
@@ -244,18 +255,17 @@ void dbg_plugin_add_hook(dbg_plugin_hook_t *fct)
 void dbg_print_plugin(FILE *fp)
 {
    Plugin *plugin;
-   fprintf(fp, "Attempt to dump plugins\n");
+   fprintf(fp, "Attempt to dump plugins. Hook count=%d\n", dbg_plugin_hook_count);
 
    if (!plugin_list) {
       return;
    }
-
    foreach_alist(plugin, plugin_list) {
       for(int i=0; i < dbg_plugin_hook_count; i++) {
-         dbg_plugin_hook_t *fct = dbg_plugin_hooks[i];
+//       dbg_plugin_hook_t *fct = dbg_plugin_hooks[i];
          fprintf(fp, "Plugin %p name=\"%s\" disabled=%d\n",
                  plugin, plugin->file, plugin->disabled);
-         fct(plugin, fp);
+//       fct(plugin, fp);
       }
    }
 }