qemuAgentCommand(qemuAgentPtr agent,
virJSONValuePtr cmd,
virJSONValuePtr *reply,
- bool needReply,
int seconds)
{
int ret = -1;
int await_event = agent->await_event;
*reply = NULL;
+ memset(&msg, 0, sizeof(msg));
if (!agent->running) {
virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s",
_("Guest agent disappeared while executing command"));
- return -1;
+ goto cleanup;
}
if (qemuAgentGuestSync(agent) < 0)
return -1;
- memset(&msg, 0, sizeof(msg));
-
if (!(cmdstr = virJSONValueToString(cmd, false)))
goto cleanup;
msg.txBuffer = g_strdup_printf("%s" LINE_ENDING, cmdstr);
VIR_DEBUG("Receive command reply ret=%d rxObject=%p",
ret, msg.rxObject);
- if (ret == 0) {
- /* If we haven't obtained any reply but we wait for an
- * event, then don't report this as error */
- if (!msg.rxObject) {
- if (await_event && !needReply) {
- VIR_DEBUG("Woken up by event %d", await_event);
+ if (ret < 0)
+ goto cleanup;
+
+ /* If we haven't obtained any reply but we wait for an
+ * event, then don't report this as error */
+ if (!msg.rxObject) {
+ if (!await_event) {
+ if (agent->running) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Missing agent reply object"));
} else {
- if (agent->running)
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Missing agent reply object"));
- else
- virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s",
- _("Guest agent disappeared while executing command"));
- ret = -1;
+ virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s",
+ _("Guest agent disappeared while executing command"));
}
- } else {
- *reply = msg.rxObject;
- ret = qemuAgentCheckError(cmd, *reply);
+ ret = -1;
}
+ goto cleanup;
}
+ *reply = msg.rxObject;
+ ret = qemuAgentCheckError(cmd, *reply);
+
cleanup:
VIR_FREE(cmdstr);
VIR_FREE(msg.txBuffer);
+ agent->await_event = QEMU_AGENT_EVENT_NONE;
return ret;
}
agent->await_event = QEMU_AGENT_EVENT_RESET;
else
agent->await_event = QEMU_AGENT_EVENT_SHUTDOWN;
- ret = qemuAgentCommand(agent, cmd, &reply, false,
+ ret = qemuAgentCommand(agent, cmd, &reply,
VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN);
virJSONValueFree(cmd);
if (!cmd)
goto cleanup;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0)
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup;
if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) {
if (!cmd)
return -1;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0)
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup;
if (virJSONValueObjectGetNumberInt(reply, "return", &ret) < 0) {
return -1;
agent->await_event = QEMU_AGENT_EVENT_SUSPEND;
- ret = qemuAgentCommand(agent, cmd, &reply, false, agent->timeout);
+ ret = qemuAgentCommand(agent, cmd, &reply, agent->timeout);
virJSONValueFree(cmd);
virJSONValueFree(reply);
if (!(cmd = virJSONValueFromString(cmd_str)))
goto cleanup;
- if ((ret = qemuAgentCommand(agent, cmd, &reply, true, timeout)) < 0)
+ if ((ret = qemuAgentCommand(agent, cmd, &reply, timeout)) < 0)
goto cleanup;
if (!(*result = virJSONValueToString(reply, false)))
if (!cmd)
return ret;
- ret = qemuAgentCommand(agent, cmd, &reply, false, agent->timeout);
+ ret = qemuAgentCommand(agent, cmd, &reply, agent->timeout);
virJSONValueFree(cmd);
virJSONValueFree(reply);
if (!(cmd = qemuAgentMakeCommand("guest-get-vcpus", NULL)))
return -1;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0)
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup;
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
NULL)))
goto cleanup;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0)
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup;
/* All negative values are invalid. Return of 0 is bogus since we wouldn't
if (!cmd)
return ret;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0) {
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) {
if (qemuAgentErrorCommandUnsupported(reply))
ret = -2;
goto cleanup;
if (!cmd)
return ret;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0)
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup;
if (virJSONValueObjectGetNumberUlong(reply, "return", &json_time) < 0) {
if (!cmd)
return ret;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0)
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup;
ret = 0;
if (!cmd)
return ret;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0) {
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) {
if (qemuAgentErrorCommandUnsupported(reply))
ret = -2;
goto cleanup;
if (!(cmd = qemuAgentMakeCommand("guest-network-get-interfaces", NULL)))
goto cleanup;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0)
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup;
if (!(ret_array = virJSONValueObjectGet(reply, "return"))) {
NULL)))
goto cleanup;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0)
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0)
goto cleanup;
ret = 0;
if (!(cmd = qemuAgentMakeCommand("guest-get-users", NULL)))
return -1;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0) {
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) {
if (qemuAgentErrorCommandUnsupported(reply))
return -2;
return -1;
if (!(cmd = qemuAgentMakeCommand("guest-get-osinfo", NULL)))
return -1;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0) {
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) {
if (qemuAgentErrorCommandUnsupported(reply))
return -2;
return -1;
if (!(cmd = qemuAgentMakeCommand("guest-get-timezone", NULL)))
return -1;
- if (qemuAgentCommand(agent, cmd, &reply, true, agent->timeout) < 0) {
+ if (qemuAgentCommand(agent, cmd, &reply, agent->timeout) < 0) {
if (qemuAgentErrorCommandUnsupported(reply))
return -2;
return -1;