]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: don't override earlier json error
authorEric Blake <eblake@redhat.com>
Fri, 22 Feb 2013 16:41:38 +0000 (09:41 -0700)
committerEric Blake <eblake@redhat.com>
Tue, 26 Feb 2013 00:36:03 +0000 (17:36 -0700)
I built without yajl support, and noticed a strange failure message
in qemumonitorjsontest:

2013-02-22 16:12:37.503+0000: 19812: error : virJSONValueToString:1119 : internal error No JSON parser implementation is available
2013-02-22 16:12:37.503+0000: 19812: error : qemuMonitorJSONCommandWithFd:253 : out of memory

While a later patch will fix the test to skip when json is not present,
this patch avoids overriding the more useful error message from
virJSONValueToString returning NULL.

* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCommandWithFd):
Don't override message.
(qemuMonitorJSONCheckError): Don't print NULL.
* src/qemu/qemu_agent.c (qemuAgentCommand): Don't override message.
(qemuAgentCheckError): Don't print NULL.
(qemuAgentArbitraryCommand): Properly fail on OOM.

src/qemu/qemu_agent.c
src/qemu/qemu_monitor_json.c

index ebe777b3bc0daf122492c8231b46cb067ac84fc3..3e26cf14a6c97daaca353852530504f8cece033e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * qemu_agent.h: interaction with QEMU guest agent
  *
- * Copyright (C) 2006-2012 Red Hat, Inc.
+ * Copyright (C) 2006-2013 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -985,10 +985,8 @@ qemuAgentCommand(qemuAgentPtr mon,
 
     memset(&msg, 0, sizeof(msg));
 
-    if (!(cmdstr = virJSONValueToString(cmd, false))) {
-        virReportOOMError();
+    if (!(cmdstr = virJSONValueToString(cmd, false)))
         goto cleanup;
-    }
     if (virAsprintf(&msg.txBuffer, "%s" LINE_ENDING, cmdstr) < 0) {
         virReportOOMError();
         goto cleanup;
@@ -1104,7 +1102,7 @@ qemuAgentCheckError(virJSONValuePtr cmd,
 
         /* Log the full JSON formatted command & error */
         VIR_DEBUG("unable to execute QEMU agent command %s: %s",
-                  cmdstr, replystr);
+                  NULLSTR(cmdstr), NULLSTR(replystr));
 
         /* Only send the user the command name + friendly error */
         if (!error)
@@ -1125,7 +1123,7 @@ qemuAgentCheckError(virJSONValuePtr cmd,
         char *replystr = virJSONValueToString(reply, false);
 
         VIR_DEBUG("Neither 'return' nor 'error' is set in the JSON reply %s: %s",
-                  cmdstr, replystr);
+                  NULLSTR(cmdstr), NULLSTR(replystr));
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unable to execute QEMU agent command '%s'"),
                        qemuAgentCommandName(cmd));
@@ -1420,7 +1418,8 @@ qemuAgentArbitraryCommand(qemuAgentPtr mon,
 
     if (ret == 0) {
         ret = qemuAgentCheckError(cmd, reply);
-        *result = virJSONValueToString(reply, false);
+        if (!(*result = virJSONValueToString(reply, false)))
+            ret = -1;
     }
 
     virJSONValueFree(cmd);
index 50ce34735b95aff16ba97b904b784a7bab1f2c9c..9991a0a644365db6ada66ea8ad618d7319a97d56 100644 (file)
@@ -249,10 +249,8 @@ qemuMonitorJSONCommandWithFd(qemuMonitorPtr mon,
         }
     }
 
-    if (!(cmdstr = virJSONValueToString(cmd, false))) {
-        virReportOOMError();
+    if (!(cmdstr = virJSONValueToString(cmd, false)))
         goto cleanup;
-    }
     if (virAsprintf(&msg.txBuffer, "%s\r\n", cmdstr) < 0) {
         virReportOOMError();
         goto cleanup;
@@ -339,7 +337,7 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
 
         /* Log the full JSON formatted command & error */
         VIR_DEBUG("unable to execute QEMU command %s: %s",
-                  cmdstr, replystr);
+                  NULLSTR(cmdstr), NULLSTR(replystr));
 
         /* Only send the user the command name + friendly error */
         if (!error)
@@ -360,7 +358,7 @@ qemuMonitorJSONCheckError(virJSONValuePtr cmd,
         char *replystr = virJSONValueToString(reply, false);
 
         VIR_DEBUG("Neither 'return' nor 'error' is set in the JSON reply %s: %s",
-                  cmdstr, replystr);
+                  NULLSTR(cmdstr), NULLSTR(replystr));
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unable to execute QEMU command '%s'"),
                        qemuMonitorJSONCommandName(cmd));