]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Find helpers at runtime
authorAndrea Bolognani <abologna@redhat.com>
Tue, 25 Apr 2023 14:38:53 +0000 (16:38 +0200)
committerAndrea Bolognani <abologna@redhat.com>
Wed, 10 May 2023 16:54:09 +0000 (18:54 +0200)
Use the recently introduced virFindFileInPathFull() function to
discover the path for qemu-bridge-helper and qemu-pr-helper at
runtime.

Note that it's still possible for the administrator to prevent
this lookup and use arbitrary binaries by setting the
appropriate keys in qemu.conf: this simply removes the need to
perform the lookup at build time, and thus to have the helpers
installed in the build environment.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/qemu/qemu_interface.c
src/qemu/qemu_process.c

index e395bfcc5b47a2e8405174cbfbe841d6cc291f79..e875de48eeccb18bc5122b769a3736efa36e0252 100644 (file)
@@ -327,7 +327,14 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfig *cfg,
                                  int *tapfd,
                                  unsigned int flags)
 {
+    const char *const bridgeHelperDirs[] = {
+        "/usr/libexec",
+        "/usr/lib/qemu",
+        "/usr/lib",
+        NULL,
+    };
     g_autoptr(virCommand) cmd = NULL;
+    g_autofree char *bridgeHelperPath = NULL;
     char *errbuf = NULL, *cmdstr = NULL;
     int pair[2] = { -1, -1 };
 
@@ -339,13 +346,17 @@ qemuCreateInBridgePortWithHelper(virQEMUDriverConfig *cfg,
         return -1;
     }
 
-    if (!virFileIsExecutable(cfg->bridgeHelperName)) {
+    bridgeHelperPath = virFindFileInPathFull(cfg->bridgeHelperName, bridgeHelperDirs);
+
+    if (!bridgeHelperPath) {
         virReportSystemError(errno, _("'%1$s' is not a suitable bridge helper"),
                              cfg->bridgeHelperName);
         return -1;
     }
 
-    cmd = virCommandNew(cfg->bridgeHelperName);
+    VIR_DEBUG("Using qemu-bridge-helper: %s", bridgeHelperPath);
+
+    cmd = virCommandNew(bridgeHelperPath);
     if (flags & VIR_NETDEV_TAP_CREATE_VNET_HDR)
         virCommandAddArgFormat(cmd, "--use-vnet");
     virCommandAddArgFormat(cmd, "--br=%s", brname);
index 952814d6637fecccba328d64c66e8bde5a0c763c..bb4cf352269d21e2f78f7ad8bbfa6ac5fef63ada 100644 (file)
@@ -2818,10 +2818,15 @@ qemuProcessStartPRDaemonHook(void *opaque)
 int
 qemuProcessStartManagedPRDaemon(virDomainObj *vm)
 {
+    const char *const prHelperDirs[] = {
+        "/usr/libexec",
+        NULL,
+    };
     qemuDomainObjPrivate *priv = vm->privateData;
     virQEMUDriver *driver = priv->driver;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;
     int errfd = -1;
+    g_autofree char *prHelperPath = NULL;
     g_autofree char *pidfile = NULL;
     g_autofree char *socketPath = NULL;
     pid_t cpid = -1;
@@ -2832,12 +2837,16 @@ qemuProcessStartManagedPRDaemon(virDomainObj *vm)
 
     cfg = virQEMUDriverGetConfig(driver);
 
-    if (!virFileIsExecutable(cfg->prHelperName)) {
+    prHelperPath = virFindFileInPathFull(cfg->prHelperName, prHelperDirs);
+
+    if (!prHelperPath) {
         virReportSystemError(errno, _("'%1$s' is not a suitable pr helper"),
                              cfg->prHelperName);
         goto cleanup;
     }
 
+    VIR_DEBUG("Using qemu-pr-helper: %s", prHelperPath);
+
     if (!(pidfile = qemuProcessBuildPRHelperPidfilePath(vm)))
         goto cleanup;
 
@@ -2853,7 +2862,7 @@ qemuProcessStartManagedPRDaemon(virDomainObj *vm)
         goto cleanup;
     }
 
-    if (!(cmd = virCommandNewArgList(cfg->prHelperName,
+    if (!(cmd = virCommandNewArgList(prHelperPath,
                                      "-k", socketPath,
                                      NULL)))
         goto cleanup;
@@ -2881,7 +2890,7 @@ qemuProcessStartManagedPRDaemon(virDomainObj *vm)
     if (virPidFileReadPath(pidfile, &cpid) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("pr helper %1$s didn't show up"),
-                       cfg->prHelperName);
+                       prHelperPath);
         goto cleanup;
     }
 
@@ -2899,7 +2908,7 @@ qemuProcessStartManagedPRDaemon(virDomainObj *vm)
         if (saferead(errfd, errbuf, sizeof(errbuf) - 1) < 0) {
             virReportSystemError(errno,
                                  _("pr helper %1$s died unexpectedly"),
-                                 cfg->prHelperName);
+                                 prHelperPath);
         } else {
             virReportError(VIR_ERR_OPERATION_FAILED,
                            _("pr helper died and reported: %1$s"), errbuf);