mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemuAgentGetHostname: Refactor to remove cleanup section
Use g_autoptr instead. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
060d49d7b0
commit
280aa14dd8
@ -1720,44 +1720,36 @@ int
|
|||||||
qemuAgentGetHostname(qemuAgentPtr agent,
|
qemuAgentGetHostname(qemuAgentPtr agent,
|
||||||
char **hostname)
|
char **hostname)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autoptr(virJSONValue) cmd = qemuAgentMakeCommand("guest-get-host-name", NULL);
|
||||||
virJSONValuePtr cmd;
|
g_autoptr(virJSONValue) reply = NULL;
|
||||||
virJSONValuePtr reply = NULL;
|
|
||||||
virJSONValuePtr data = NULL;
|
virJSONValuePtr data = NULL;
|
||||||
const char *result = NULL;
|
const char *result = NULL;
|
||||||
|
|
||||||
cmd = qemuAgentMakeCommand("guest-get-host-name",
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
return ret;
|
return -1;
|
||||||
|
|
||||||
if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) {
|
if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) {
|
||||||
if (qemuAgentErrorCommandUnsupported(reply))
|
if (qemuAgentErrorCommandUnsupported(reply))
|
||||||
ret = -2;
|
return -2;
|
||||||
goto cleanup;
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(data = virJSONValueObjectGet(reply, "return"))) {
|
if (!(data = virJSONValueObjectGet(reply, "return"))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("malformed return value"));
|
_("malformed return value"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(result = virJSONValueObjectGetString(data, "host-name"))) {
|
if (!(result = virJSONValueObjectGetString(data, "host-name"))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("'host-name' missing in guest-get-host-name reply"));
|
_("'host-name' missing in guest-get-host-name reply"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*hostname = g_strdup(result);
|
*hostname = g_strdup(result);
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
virJSONValueFree(cmd);
|
|
||||||
virJSONValueFree(reply);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user