#include <string.h>
#include <stddef.h>
#include <dlfcn.h>
+#include <sys/stat.h>
#include "debug.h"
#include "prio.h"
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);
}
struct prio * add_prio (char * name)
{
char libname[LIB_PRIO_NAMELEN];
+ struct stat stbuf;
struct prio * p;
char *errstr;
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)