From: Michal Privoznik Date: Fri, 22 Aug 2014 09:37:51 +0000 (+0200) Subject: virDriverLoadModule: Honor libvirt func name tranlsation X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=27d59ab7cd5ccf31ae324c918933f53cac13fcaa;p=libvirt.git virDriverLoadModule: Honor libvirt func name tranlsation There's this unwritten rule in libvirt that vir_function is translated into virFunction when needed (e.g. in remote protocol definition, python, ...). Up till now we ignored such translation in driver module loading and did fine. Well, we didn't have any module with an underscore in its name. But this will change in next commit. The problem is, once an a module is dlopen()-ed, we derive register function name from its name. So instead of "driver_subdriverRegister" do some magic to turn that into "driverSubdriverRegister". Signed-off-by: Michal Privoznik --- diff --git a/src/driver.c b/src/driver.c index 9e3a2eb1dc..71569e6eaa 100644 --- a/src/driver.c +++ b/src/driver.c @@ -23,6 +23,7 @@ #include #include +#include #include "driver.h" #include "viralloc.h" @@ -45,7 +46,8 @@ VIR_LOG_INIT("driver"); void * virDriverLoadModule(const char *name) { - char *modfile = NULL, *regfunc = NULL; + char *modfile = NULL, *regfunc = NULL, *fixedname = NULL; + char *tmp; void *handle = NULL; int (*regsym)(void); @@ -72,7 +74,18 @@ virDriverLoadModule(const char *name) goto cleanup; } - if (virAsprintfQuiet(®func, "%sRegister", name) < 0) { + 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; } @@ -89,11 +102,13 @@ virDriverLoadModule(const char *name) 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;