提交 27d59ab7 编写于 作者: M Michal Privoznik 提交者: Martin Kletzander

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: NMichal Privoznik <mprivozn@redhat.com>
上级 5feaef17
......@@ -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(&regfunc, "%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(&regfunc, "%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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册