Skip to content

Commit

Permalink
dird: 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 bc850fd commit 0b8475d
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/cats/cats_backends.c
Expand Up @@ -98,6 +98,7 @@ B_DB *db_init_database(JCR *jcr,
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 @@ -171,8 +172,11 @@ B_DB *db_init_database(JCR *jcr,
#endif
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 @@ -181,8 +185,11 @@ B_DB *db_init_database(JCR *jcr,
*/
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 @@ -193,8 +200,11 @@ B_DB *db_init_database(JCR *jcr,
*/
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 0b8475d

Please sign in to comment.