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

[libvirt] [PATCH] More advanced auto-detection of driver module directory



From: "Daniel P. Berrange" <berrange redhat com>

When running directly from GIT, libvirtd attempts to locate
the directory containing loadable modules. This currently
only works if executing libvirtd with a CWD inside the libvirt
source tree. Switch to locate based on the path to the current
binary instead
---
 daemon/libvirtd.c |   24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index b5c0102..a7bb9dd 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -972,9 +972,27 @@ int main(int argc, char **argv) {
     virLogSetFromEnv();
 
 #ifdef WITH_DRIVER_MODULES
-    if (strstr(argv[0], "lt-libvirtd") &&
-        (access("./.git", R_OK) >= 0 || access("../.git", R_OK) >= 0))
-        virDriverModuleInitialize("./src/.libs");
+    if (strstr(argv[0], "lt-libvirtd")) {
+        char *tmp = strrchr(argv[0], '/');
+        if (!tmp) {
+            fprintf(stderr, _("%s: cannot identify driver directory\n"), argv[0]);
+            exit(EXIT_FAILURE);
+        }
+        *tmp = '\0';
+        char *driverdir;
+        if (virAsprintf(&driverdir, "%s/../../src/.libs", argv[0]) < 0) {
+            fprintf(stderr, _("%s: initialization failed\n"), argv[0]);
+            exit(EXIT_FAILURE);
+        }
+        if (access(driverdir, R_OK) < 0) {
+            fprintf(stderr, _("%s: expected driver directory '%s' is missing\n"),
+                    argv[0], driverdir);
+            exit(EXIT_FAILURE);
+        }
+        virDriverModuleInitialize(driverdir);
+        *tmp = '/';
+        /* Must not free 'driverdir' - it is still used */
+    }
 #endif
 
     while (1) {
-- 
1.7.10.4


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