]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/plugins.c
kes Apply Marco van Wieringen's set of patches, cleans up Migration/Copy
[bacula/bacula] / bacula / src / lib / plugins.c
index c67228e6fd6feb33071098f435d777166c4869ad..2a135dd470b289d50f3669315ddb7e2894743122 100644 (file)
@@ -20,7 +20,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 #include "bacula.h"
 #include "plugins.h"
 
+static const int dbglvl = 50;
+
 /* All loaded plugins */
-alist *plugin_list;
+alist *plugin_list = NULL;
 
 /*
  * Create a new plugin "class" entry and enter it in the
@@ -58,7 +60,6 @@ Plugin *new_plugin()
 bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char *type)
 {
    bool found = false;
-#ifndef HAVE_WIN32
    t_loadPlugin loadPlugin;
    Plugin *plugin;
    DIR* dp = NULL;
@@ -77,7 +78,9 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char
 
    if (!(dp = opendir(plugin_dir))) {
       berrno be;
-      Jmsg(NULL, M_ERROR, 0, _("Failed to open Plugin directory %s: ERR=%s\n"), 
+      Jmsg(NULL, M_ERROR_TERM, 0, _("Failed to open Plugin directory %s: ERR=%s\n"), 
+            plugin_dir, be.bstrerror());
+      Dmsg2(dbglvl, "Failed to open Plugin directory %s: ERR=%s\n", 
             plugin_dir, be.bstrerror());
       goto get_out;
    }
@@ -90,8 +93,9 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char
    for ( ;; ) {
       if ((readdir_r(dp, entry, &result) != 0) || (result == NULL)) {
          if (!found) {
-            Jmsg(NULL, M_INFO, 0, _("Failed to find suitable plugin in %s\n"), 
+            Jmsg(NULL, M_WARNING, 0, _("Failed to find any plugins in %s\n"), 
                   plugin_dir);
+            Dmsg1(dbglvl, "Failed to find any plugins in %s\n", plugin_dir);
          }
          break;
       }
@@ -103,9 +107,10 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char
       len = strlen(result->d_name);
       type_len = strlen(type);
       if (len < type_len+1 || strcmp(&result->d_name[len-type_len], type) != 0) {
+         Dmsg3(dbglvl, "Rejected plugin: want=%s name=%s len=%d\n", type, result->d_name, len);
          continue;
       }
-      printf("Got: name=%s len=%d\n", result->d_name, len);
+      Dmsg2(dbglvl, "Loaded plugin: name=%s len=%d\n", result->d_name, len);
        
       pm_strcpy(fname, plugin_dir);
       if (need_slash) {
@@ -121,7 +126,9 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char
       plugin->pHandle = dlopen(fname.c_str(), RTLD_NOW);
       if (!plugin->pHandle) {
          Jmsg(NULL, M_ERROR, 0, _("Plugin load %s failed: ERR=%s\n"), 
-              fname.c_str(), dlerror());
+              fname.c_str(), NPRT(dlerror()));
+         Dmsg2(dbglvl, "Plugin load %s failed: ERR=%s\n", fname.c_str(), 
+               NPRT(dlerror()));
          goto get_out;
       }
 
@@ -129,13 +136,17 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char
       loadPlugin = (t_loadPlugin)dlsym(plugin->pHandle, "loadPlugin");
       if (!loadPlugin) {
          Jmsg(NULL, M_ERROR, 0, _("Lookup of loadPlugin in plugin %s failed: ERR=%s\n"),
-            fname.c_str(), dlerror());
+            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;
       }
       plugin->unloadPlugin = (t_unloadPlugin)dlsym(plugin->pHandle, "unloadPlugin");
       if (!plugin->unloadPlugin) {
          Jmsg(NULL, M_ERROR, 0, _("Lookup of unloadPlugin in plugin %s failed: ERR=%s\n"),
-            fname.c_str(), dlerror());
+            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;
       }
 
@@ -152,7 +163,6 @@ get_out:
    if (dp) {
       closedir(dp);
    }
-#endif
    return found;
 }
 
@@ -161,9 +171,11 @@ get_out:
  */
 void unload_plugins()
 {
-#ifndef HAVE_WIN32
    Plugin *plugin;
 
+   if (!plugin_list) {
+      return;
+   }
    foreach_alist(plugin, plugin_list) {
       /* Shut it down and unload it */
       plugin->unloadPlugin();
@@ -175,5 +187,4 @@ void unload_plugins()
    }
    delete plugin_list;
    plugin_list = NULL;
-#endif
 }