]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: fix bhyveConnectAgent() master
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Sun, 14 Jun 2026 05:58:10 +0000 (07:58 +0200)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Mon, 15 Jun 2026 16:48:52 +0000 (18:48 +0200)
The bhyveConnectAgent() function calls qemuAgentOpen() to open an agent
connection. If it fails, e.g. because of insufficient permissions to
open the socket, it returns NULL. Currently, if that happens,
bhyveConnectAgent() just sets agentError to true and exits with 0.
This does not match the contract of bhyveDomainEnsureAgent(), which
should either provide an agent connection or fail.

Fix that by returning -1 when qemuAgentOpen() fails. To make intent
clearer, add a documentation for bhyveConnectAgent().

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/bhyve/bhyve_process.c

index e92bdeb416990ad799fd7dc1cec18ab397e3f830..2221d8700a20715e3fdd69fd484ad67940296de4 100644 (file)
@@ -238,6 +238,18 @@ static qemuAgentCallbacks agentCallbacks = {
     .errorNotify = bhyveProcessHandleAgentError,
 };
 
+/**
+ * bhyveConnectAgent:
+ * @driver: driver object
+ * @vm: domain object
+ *
+ * Connect to the guest agent via the UNIX socket specified in the domain
+ * definition. On success, bhyveDomainObjPrivate's agent field should
+ * point to the agent instance.
+ *
+ * Returns: 0 on success,
+ *          -1 on error
+ */
 int
 bhyveConnectAgent(struct _bhyveConn *driver G_GNUC_UNUSED, virDomainObj *vm)
 {
@@ -269,9 +281,10 @@ bhyveConnectAgent(struct _bhyveConn *driver G_GNUC_UNUSED, virDomainObj *vm)
 
     priv->agent = agent;
     if (!priv->agent) {
-        VIR_WARN("Cannot connect to QEMU guest agent for %s", vm->def->name);
-        priv->agentError = true;
-        virResetLastError();
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Cannot connect to QEMU guest agent for %1$s"),
+                       vm->def->name);
+        return -1;
     }
 
     return 0;