static void * virDriverLoadModuleFile(const char *file) { void *handle = NULL; VIR_DEBUG("Load module file '%s'", file); if (access(file, R_OK) < 0) { VIR_INFO("Module %s not accessible", file); return NULL; } virUpdateSelfLastChanged(file); if (!(handle = dlopen(file, RTLD_NOW | RTLD_GLOBAL))) VIR_ERROR(_("failed to load module %s %s"), file, dlerror()); return handle; }
void * virDriverLoadModule(const char *name) { char *modfile = NULL, *regfunc = NULL, *fixedname = NULL; char *tmp; void *handle = NULL; int (*regsym)(void); VIR_DEBUG("Module load %s", name); if (!(modfile = virFileFindResourceFull(name, "libvirt_driver_", ".so", abs_topbuilddir "/src/.libs", DEFAULT_DRIVER_DIR, "LIBVIRT_DRIVER_DIR"))) return NULL; if (access(modfile, R_OK) < 0) { VIR_INFO("Module %s not accessible", modfile); goto cleanup; } virUpdateSelfLastChanged(modfile); handle = dlopen(modfile, RTLD_NOW | RTLD_GLOBAL); if (!handle) { VIR_ERROR(_("failed to load module %s %s"), modfile, dlerror()); goto cleanup; } if (VIR_STRDUP_QUIET(fixedname, name) < 0) { VIR_ERROR(_("out of memory")); goto cleanup; } /* convert something_like_this into somethingLikeThis */ while ((tmp = strchr(fixedname, '_'))) { memmove(tmp, tmp + 1, strlen(tmp)); *tmp = c_toupper(*tmp); } if (virAsprintfQuiet(®func, "%sRegister", fixedname) < 0) goto cleanup; regsym = dlsym(handle, regfunc); if (!regsym) { VIR_ERROR(_("Missing module registration symbol %s"), regfunc); goto cleanup; } if ((*regsym)() < 0) { VIR_ERROR(_("Failed module registration %s"), regfunc); goto cleanup; } VIR_FREE(modfile); VIR_FREE(regfunc); VIR_FREE(fixedname); return handle; cleanup: VIR_FREE(modfile); VIR_FREE(regfunc); VIR_FREE(fixedname); if (handle) dlclose(handle); return NULL; }