Skip to content

Commit

Permalink
stored: Show the output of dlerror() correctly.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pstorz authored and Marco van Wieringen committed Apr 27, 2016
1 parent 0b8475d commit f0de1f7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/stored/sd_backends.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit f0de1f7

Please sign in to comment.