[libvirt] [PATCH 1/5] qemu: don't override earlier json error

Eric Blake eblake at redhat.com
Fri Feb 22 23:09:05 UTC 2013


I built without json 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        | 13 ++++++-------
 src/qemu/qemu_monitor_json.c |  8 +++-----
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index ebe777b..3e26cf1 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -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);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index f712321..b950b87 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -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));
-- 
1.8.1.2




More information about the libvir-list mailing list