]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/plugins.c
Add missing files for xattr and eliminate a few compiler complaints
[bacula/bacula] / bacula / src / lib / plugins.c
index 2a135dd470b289d50f3669315ddb7e2894743122..d56b41ade252328401aaaf80d658c5f13ff35abe 100644 (file)
  *
  * Kern Sibbald, October 2007
  */
+
 #include "bacula.h"
+#include <dlfcn.h>
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#define NAMELEN(dirent) (strlen((dirent)->d_name))
+#endif
+#ifndef HAVE_READDIR_R
+int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
+#endif
+
+#ifndef RTLD_NOW
+#define RTLD_NOW 2
+#endif
+
 #include "plugins.h"
 
 static const int dbglvl = 50;
@@ -49,7 +63,6 @@ Plugin *new_plugin()
 
    plugin = (Plugin *)malloc(sizeof(Plugin));
    memset(plugin, 0, sizeof(Plugin));
-   plugin_list->append(plugin);
    return plugin;
 }
 
@@ -61,7 +74,7 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char
 {
    bool found = false;
    t_loadPlugin loadPlugin;
-   Plugin *plugin;
+   Plugin *plugin = NULL;
    DIR* dp = NULL;
    struct dirent *entry = NULL, *result;
    int name_max;
@@ -151,12 +164,18 @@ bool load_plugins(void *binfo, void *bfuncs, const char *plugin_dir, const char
       }
 
       /* Initialize the plugin */
-      loadPlugin(binfo, bfuncs, &plugin->pinfo, &plugin->pfuncs);
+      if (loadPlugin(binfo, bfuncs, &plugin->pinfo, &plugin->pfuncs) != bRC_OK) {
+         goto get_out;
+      }
 
       found = true;                /* found a plugin */
+      plugin_list->append(plugin);
    }
 
 get_out:
+   if (!found && plugin) {
+      free(plugin);
+   }
    if (entry) {
       free(entry);
    }
@@ -188,3 +207,37 @@ void unload_plugins()
    delete plugin_list;
    plugin_list = NULL;
 }
+
+/*
+ * Dump plugin information
+ * Each daemon can register a hook that will be called
+ * after a fatal signal.
+ */
+#define DBG_MAX_HOOK 10
+static dbg_plugin_hook_t *dbg_plugin_hooks[DBG_MAX_HOOK];
+static int dbg_plugin_hook_count=0;
+
+void dbg_plugin_add_hook(dbg_plugin_hook_t *fct)
+{
+   ASSERT(dbg_plugin_hook_count < DBG_MAX_HOOK);
+   dbg_plugin_hooks[dbg_plugin_hook_count++] = fct;
+}
+
+void _dbg_print_plugin(FILE *fp)
+{
+   Plugin *plugin;
+   fprintf(fp, "Attempt to dump plugins\n");
+
+   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];
+         fprintf(fp, "Plugin %p name=\"%s\" disabled=%d\n",
+                 plugin, plugin->file, plugin->disabled);
+         fct(plugin, fp);
+      }
+   }
+}