mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 19:02:25 +00:00
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 <mprivozn@redhat.com>
This commit is contained in:
parent
5feaef1776
commit
27d59ab7cd
19
src/driver.c
19
src/driver.c
@ -23,6 +23,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <c-ctype.h>
|
||||
|
||||
#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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user