From f0de1f7245474c5aa9398e5e418e0b06cff93812 Mon Sep 17 00:00:00 2001 From: Philipp Storz Date: Wed, 27 Apr 2016 09:28:28 +0200 Subject: [PATCH] stored: Show the output of dlerror() correctly. As we use NPRT(dlerror()) we call dlerror() twice while expanding the NPRT() macro and the manual page of dlerror() says: The returned string contains no trailing newline. If no dynamic linking errors have occurred since the last invocation of dlerror(), dlerror() returns NULL. Thus, invoking dlerror() a second time, immediately following a prior invocation, results in NULL being returned. --- src/stored/sd_backends.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/stored/sd_backends.c b/src/stored/sd_backends.c index 8c36a7338d1..cc54c15ba87 100644 --- a/src/stored/sd_backends.c +++ b/src/stored/sd_backends.c @@ -73,6 +73,7 @@ DEVICE *init_backend_dev(JCR *jcr, int device_type) char *backend_dir; void *dl_handle = NULL; POOL_MEM shared_library_name(PM_FNAME); + POOL_MEM error(PM_FNAME); backend_interface_mapping_t *backend_interface_mapping; backend_shared_library_t *backend_shared_library; t_backend_instantiate backend_instantiate; @@ -117,8 +118,11 @@ DEVICE *init_backend_dev(JCR *jcr, int device_type) if (stat(shared_library_name.c_str(), &st) == 0) { dl_handle = dlopen(shared_library_name.c_str(), RTLD_NOW); if (!dl_handle) { + pm_strcpy(error, dlerror()); Jmsg(jcr, M_ERROR, 0, _("Unable to load shared library: %s ERR=%s\n"), - shared_library_name.c_str(), NPRT(dlerror())); + shared_library_name.c_str(), error.c_str()); + Dmsg2(100, _("Unable to load shared library: %s ERR=%s\n"), + shared_library_name.c_str(), error.c_str()); continue; } @@ -127,8 +131,11 @@ DEVICE *init_backend_dev(JCR *jcr, int device_type) */ backend_instantiate = (t_backend_instantiate)dlsym(dl_handle, "backend_instantiate"); if (backend_instantiate == NULL) { + pm_strcpy(error, dlerror()); Jmsg(jcr, M_ERROR, 0, _("Lookup of backend_instantiate in shared library %s failed: ERR=%s\n"), - shared_library_name.c_str(), NPRT(dlerror())); + shared_library_name.c_str(), error.c_str()); + Dmsg2(100, _("Lookup of backend_instantiate in shared library %s failed: ERR=%s\n"), + shared_library_name.c_str(), error.c_str()); dlclose(dl_handle); dl_handle = NULL; continue; @@ -139,8 +146,11 @@ DEVICE *init_backend_dev(JCR *jcr, int device_type) */ flush_backend = (t_flush_backend)dlsym(dl_handle, "flush_backend"); if (flush_backend == NULL) { + pm_strcpy(error, dlerror()); Jmsg(jcr, M_ERROR, 0, _("Lookup of flush_backend in shared library %s failed: ERR=%s\n"), - shared_library_name.c_str(), NPRT(dlerror())); + shared_library_name.c_str(), error.c_str()); + Dmsg2(100, _("Lookup of flush_backend in shared library %s failed: ERR=%s\n"), + shared_library_name.c_str(), error.c_str()); dlclose(dl_handle); dl_handle = NULL; continue;