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>
---
src/qemu/qemu_interface.c | 15 +++++++++++++--
src/qemu/qemu_process.c | 17 +++++++++++++----
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index e395bfcc5b..e875de48ee 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -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);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 952814d663..bb4cf35226 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -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);
--
2.40.1
© 2016 - 2024 Red Hat, Inc.