Checker name is not displayed on failure
authorHannes Reinecke <hare@suse.de>
Tue, 13 Jan 2009 14:28:23 +0000 (15:28 +0100)
committerHannes Reinecke <hare@suse.de>
Tue, 17 May 2011 10:48:06 +0000 (12:48 +0200)
If add_checker() isn't able to locate the checker
it won't display the name in free_checker().

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/prio.c

index 13e6823..61c19b7 100644 (file)
@@ -2,6 +2,7 @@
 #include <string.h>
 #include <stddef.h>
 #include <dlfcn.h>
+#include <sys/stat.h>
 
 #include "debug.h"
 #include "prio.h"
@@ -18,14 +19,24 @@ int init_prio (void)
 
 static struct prio * alloc_prio (void)
 {
-       return MALLOC(sizeof(struct prio));
+       struct prio *p;
+
+       p = MALLOC(sizeof(struct prio));
+       if (p)
+               INIT_LIST_HEAD(&p->node);
+       return p;
 }
 
 void free_prio (struct prio * p)
 {
+       condlog(3, "unloading %s prioritizer", p->name);
        list_del(&p->node);
-       if (p->handle)
-               dlclose(p->handle);
+       if (p->handle) {
+               if (dlclose(p->handle) != 0) {
+                       condlog(0, "Cannot unload prioritizer %s: %s",
+                               p->name, dlerror());
+               }
+       }
        FREE(p);
 }
 
@@ -58,6 +69,7 @@ int prio_set_args (struct prio * p, char * args)
 struct prio * add_prio (char * name)
 {
        char libname[LIB_PRIO_NAMELEN];
+       struct stat stbuf;
        struct prio * p;
        char *errstr;
 
@@ -66,13 +78,19 @@ struct prio * add_prio (char * name)
                return NULL;
        snprintf(libname, LIB_PRIO_NAMELEN, "%s/libprio%s.so",
                 conf->multipath_dir, name);
+       if (stat(libname,&stbuf) < 0) {
+               condlog(0,"Prioritizer '%s' not found in %s",
+                       name, conf->multipath_dir);
+               goto out;
+       }
        condlog(3, "loading %s prioritizer", libname);
        p->handle = dlopen(libname, RTLD_NOW);
-       errstr = dlerror();
-       if (errstr != NULL)
-               condlog(0, "A dynamic linking error occurred: (%s)", errstr);
-       if (!p->handle)
+       if (!p->handle) {
+               if ((errstr = dlerror()) != NULL)
+                       condlog(0, "A dynamic linking error occurred: (%s)",
+                               errstr);
                goto out;
+       }
        p->getprio = (int (*)(struct path *, char *)) dlsym(p->handle, "getprio");
        errstr = dlerror();
        if (errstr != NULL)