]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Use virFileFindResource to locate iohelper for fdstream
authorNehal J Wani <nehaljw.kkd1@gmail.com>
Tue, 25 Mar 2014 08:23:15 +0000 (13:53 +0530)
committerDaniel P. Berrange <berrange@redhat.com>
Fri, 25 Apr 2014 10:59:46 +0000 (11:59 +0100)
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@redhat.com>
src/fdstream.c
src/fdstream.h
src/libvirt_private.syms
tests/fdstreamtest.c

index a244bb0d03a4bd96c1df27b289a22549f7a5eef3..fd576ef26e1339d5b317e839dd5d23bb0ad0c8b5 100644 (file)
@@ -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;
index 9c7295dfe782bea995722b6fa79fefa882829d79..69d832817e7f9da681cf1146be125163492fef78 100644 (file)
@@ -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);
 
index 9919ca40f9daf2606d4482b1400c1ad01c1bcd0e..ac7707dd79207b63e1d3abb10430b5867277bef6 100644 (file)
@@ -786,7 +786,6 @@ virFDStreamCreateFile;
 virFDStreamOpen;
 virFDStreamOpenFile;
 virFDStreamOpenPTY;
-virFDStreamSetIOHelper;
 
 
 # libvirt_internal.h
index d52b77b3b7b5f80943f20ac2066fa7c95b9ed900..56ba5d9127fa2194eefca6323a0e0f5efdde5a69 100644 (file)
@@ -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");