From 0007b15de61514fd7d21c736534334ac206e37f2 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 1 Dec 2007 11:30:20 +0000 Subject: [PATCH] Minimum cleanup of lib/plugin.c to support FreeBSD git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6007 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/lib/Makefile.in | 3 ++- bacula/src/lib/plugin.c | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/bacula/src/lib/Makefile.in b/bacula/src/lib/Makefile.in index 6da35951cf..5b7e5f08b1 100644 --- a/bacula/src/lib/Makefile.in +++ b/bacula/src/lib/Makefile.in @@ -109,7 +109,8 @@ bsnprintf: bsnprintf.o rm -f bsnprintf.o $(CXX) $(DEFS) $(DEBUG) -c $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) bsnprintf.c -plugin.o: plugin.c +plugin.o: plugin.c plugin.h + @echo "Compiling $<" $(NO_ECHO)$(CXX) -fPIC $(DEFS) $(DEBUG) -c $(WCFLAGS) $(CPPFLAGS) -I$(srcdir) -I$(basedir) $(DINCLUDE) $(CFLAGS) $< diff --git a/bacula/src/lib/plugin.c b/bacula/src/lib/plugin.c index 18704a6678..c6762620ec 100644 --- a/bacula/src/lib/plugin.c +++ b/bacula/src/lib/plugin.c @@ -60,9 +60,8 @@ bool load_plugins(void *bfuncs, const char *plugin_dir, const char *type) { t_loadPlugin loadPlugin; Plugin *plugin; - char *error; DIR* dp = NULL; - struct dirent *entry, *result; + struct dirent *entry = NULL, *result; int name_max; struct stat statp; bool found = false; @@ -79,7 +78,7 @@ bool load_plugins(void *bfuncs, const char *plugin_dir, const char *type) if (!(dp = opendir(plugin_dir))) { berrno be; - Dmsg2(29, "load_plugins: failed to open dir %s: ERR=%s\n", + Jmsg(NULL, M_ERROR, 0, _("Failed to open Plugin directory %s: ERR=%s\n"), plugin_dir, be.bstrerror()); goto get_out; } @@ -91,8 +90,10 @@ bool load_plugins(void *bfuncs, const char *plugin_dir, const char *type) entry = (struct dirent *)malloc(sizeof(struct dirent) + name_max + 1000); for ( ;; ) { if ((readdir_r(dp, entry, &result) != 0) || (result == NULL)) { - Dmsg1(129, "load_plugins: failed to find suitable file in dir %s\n", - plugin_dir); + if (!found) { + Jmsg(NULL, M_INFO, 0, _("Failed to find suitable plugin in %s\n"), + plugin_dir); + } break; } if (strcmp(result->d_name, ".") == 0 || @@ -119,19 +120,22 @@ bool load_plugins(void *bfuncs, const char *plugin_dir, const char *type) plugin->file = bstrdup(result->d_name); plugin->pHandle = dlopen(fname.c_str(), RTLD_NOW); if (!plugin->pHandle) { - printf("dlopen of %s failed: ERR=%s\n", fname.c_str(), dlerror()); + Jmsg(NULL, M_ERROR, 0, _("Plugin load %s failed: ERR=%s\n"), + fname.c_str(), dlerror()); goto get_out; } /* Get two global entry points */ loadPlugin = (t_loadPlugin)dlsym(plugin->pHandle, "loadPlugin"); - if ((error=dlerror()) != NULL) { - printf("dlsym failed: ERR=%s\n", error); + if (!loadPlugin) { + Jmsg(NULL, M_ERROR, 0, _("Lookup of loadPlugin in plugin %s failed: ERR=%s\n"), + fname.c_str(), dlerror()); goto get_out; } plugin->unloadPlugin = (t_unloadPlugin)dlsym(plugin->pHandle, "unloadPlugin"); - if ((error=dlerror()) != NULL) { - printf("dlsym failed: ERR=%s\n", error); + if (!plugin->unloadPlugin) { + Jmsg(NULL, M_ERROR, 0, _("Lookup of unloadPlugin in plugin %s failed: ERR=%s\n"), + fname.c_str(), dlerror()); goto get_out; } @@ -142,7 +146,9 @@ bool load_plugins(void *bfuncs, const char *plugin_dir, const char *type) } get_out: - free(entry); + if (entry) { + free(entry); + } if (dp) { closedir(dp); } -- 2.39.5