}
+/**
+ * qemuAgentGetHostname:
+ *
+ * Gets the guest hostname using the guest agent.
+ *
+ * Returns 0 on success and fills @hostname. On error -1 is returned with an
+ * error reported and if '@report_unsupported' is false -2 is returned if the
+ * guest agent does not support the command without reporting an error
+ */
int
qemuAgentGetHostname(qemuAgentPtr agent,
- char **hostname)
+ char **hostname,
+ bool report_unsupported)
{
g_autoptr(virJSONValue) cmd = qemuAgentMakeCommand("guest-get-host-name", NULL);
g_autoptr(virJSONValue) reply = NULL;
virJSONValuePtr data = NULL;
const char *result = NULL;
+ int rc;
if (!cmd)
return -1;
- if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) {
- if (qemuAgentErrorCommandUnsupported(reply))
- return -2;
-
- return -1;
- }
+ if ((rc = qemuAgentCommandFull(agent, cmd, &reply, agent->timeout,
+ report_unsupported)) < 0)
+ return rc;
if (!(data = virJSONValueObjectGet(reply, "return"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
goto endjob;
agent = qemuDomainObjEnterAgent(vm);
- ignore_value(qemuAgentGetHostname(agent, hostname));
+ ignore_value(qemuAgentGetHostname(agent, hostname, true));
qemuDomainObjExitAgent(vm, agent);
ret = 0;
goto exitagent;
}
if (supportedTypes & VIR_DOMAIN_GUEST_INFO_HOSTNAME) {
- rc = qemuAgentGetHostname(agent, &hostname);
+ rc = qemuAgentGetHostname(agent, &hostname, true);
if (rc < 0 && !(rc == -2 && types == 0))
goto exitagent;
}