[PATCH 6/9] Use virFileFindResource to locate iohelper for fdstream

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

 



From: Nehal J Wani <nehaljw.kkd1@xxxxxxxxx>

Instead of hardcoding LIBEXECDIR as the location of the libvirt_iohelper
binary, use virFileFindResource to optionally find it in the current
build directory.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/fdstream.c           | 21 ++++++++++-----------
 src/fdstream.h           |  3 ---
 src/libvirt_private.syms |  1 -
 tests/fdstreamtest.c     |  3 ---
 4 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/src/fdstream.c b/src/fdstream.c
index a244bb0..fd576ef 100644
--- a/src/fdstream.c
+++ b/src/fdstream.c
@@ -78,17 +78,6 @@ struct virFDStreamData {
 };
 
 
-static const char *iohelper_path = LIBEXECDIR "/libvirt_iohelper";
-
-void virFDStreamSetIOHelper(const char *path)
-{
-    if (path == NULL)
-        iohelper_path = LIBEXECDIR "/libvirt_iohelper";
-    else
-        iohelper_path = path;
-}
-
-
 static int virFDStreamRemoveCallback(virStreamPtr stream)
 {
     struct virFDStreamData *fdst = stream->privateData;
@@ -593,6 +582,7 @@ virFDStreamOpenFileInternal(virStreamPtr st,
     struct stat sb;
     virCommandPtr cmd = NULL;
     int errfd = -1;
+    char *iohelper_path = NULL;
 
     VIR_DEBUG("st=%p path=%s oflags=%x offset=%llu length=%llu mode=%o",
               st, path, oflags, offset, length, mode);
@@ -648,9 +638,17 @@ virFDStreamOpenFileInternal(virStreamPtr st,
             goto error;
         }
 
+        if (!(iohelper_path = virFileFindResource("libvirt_iohelper",
+                                                  "src",
+                                                  LIBEXECDIR)))
+            goto error;
+
         cmd = virCommandNewArgList(iohelper_path,
                                    path,
                                    NULL);
+
+        VIR_FREE(iohelper_path);
+
         virCommandAddArgFormat(cmd, "%llu", length);
         virCommandPassFD(cmd, fd,
                          VIR_COMMAND_PASS_FD_CLOSE_PARENT);
@@ -683,6 +681,7 @@ virFDStreamOpenFileInternal(virStreamPtr st,
     VIR_FORCE_CLOSE(fd);
     VIR_FORCE_CLOSE(childfd);
     VIR_FORCE_CLOSE(errfd);
+    VIR_FREE(iohelper_path);
     if (oflags & O_CREAT)
         unlink(path);
     return -1;
diff --git a/src/fdstream.h b/src/fdstream.h
index 9c7295d..69d8328 100644
--- a/src/fdstream.h
+++ b/src/fdstream.h
@@ -33,9 +33,6 @@ typedef void (*virFDStreamInternalCloseCb)(virStreamPtr st, void *opaque);
 typedef void (*virFDStreamInternalCloseCbFreeOpaque)(void *opaque);
 
 
-/* Only for use by test suite */
-void virFDStreamSetIOHelper(const char *path);
-
 int virFDStreamOpen(virStreamPtr st,
                     int fd);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1c7dd72..7415b17 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -786,7 +786,6 @@ virFDStreamCreateFile;
 virFDStreamOpen;
 virFDStreamOpenFile;
 virFDStreamOpenPTY;
-virFDStreamSetIOHelper;
 
 
 # libvirt_internal.h
diff --git a/tests/fdstreamtest.c b/tests/fdstreamtest.c
index d52b77b..56ba5d9 100644
--- a/tests/fdstreamtest.c
+++ b/tests/fdstreamtest.c
@@ -321,9 +321,6 @@ mymain(void)
 {
     char scratchdir[] = SCRATCHDIRTEMPLATE;
     int ret = 0;
-    const char *iohelper = abs_builddir "/../src/libvirt_iohelper";
-
-    virFDStreamSetIOHelper(iohelper);
 
     if (!mkdtemp(scratchdir)) {
         virFilePrintf(stderr, "Cannot create fakesysfsdir");
-- 
1.9.0

--
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]