[PATCH 2/3] virDriverLoadModule: Honor libvirt func name tranlsation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/driver.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/driver.c b/src/driver.c
index 9e3a2eb..71569e6 100644
--- a/src/driver.c
+++ b/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(&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;
-- 
1.8.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]