On 08/15/2012 03:36 AM, MATSUDA Daiki wrote:>
add qemuAgentArbitraryCommand() for general qemu agent command.
Twice the same line in the message, could be less brief, maybe :)
Signed-off-by: MATSUDA Daiki <matsudadik(a)intellilink.co.jp>
---
src/qemu/qemu_agent.c | 31 +++++++++++++++++++++++++++++++
src/qemu/qemu_agent.h | 5 +++++
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 26c2726..c634c23 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1408,3 +1408,34 @@ qemuAgentSuspend(qemuAgentPtr mon,
virJSONValueFree(reply);
return ret;
}
+
+int
+qemuAgentArbitraryCommand(qemuAgentPtr mon,
+ const char *cmd_str,
+ char **result,
+ int timeout)
+{
+ int ret = -1;
+ virJSONValuePtr cmd;
+ virJSONValuePtr reply = NULL;
+
+ if (timeout < -2)
+ return ret;
I think you can leave the test to only one layer of the code and that
would be 'qemuAgentSend'.
+
+ cmd = virJSONValueFromString(cmd_str);
+ if (!cmd)
+ return ret;
+
+ ret = qemuAgentCommand(mon, cmd, &reply, timeout);
+
+ if (ret == 0) {
+ ret = qemuAgentCheckError(cmd, reply);
+ *result = virJSONValueToString(reply);
+ } else {
+ result = NULL;
First of all, you probably wanted to do '*result = NULL', because
'result = NULL' won't do anything here, however in case of any other
failure (timeout == -3, fail in virJSONValuFromSting) you don't
guarantee the *result to be NULL, so I don't think you need to do this here.
Martin