[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 2/2] check whether qemuMonitorJSONHMP() failed



If qemu quited unexpectedly when we call qemuMonitorJSONHMP(),
libvirt will crash.
Steps to reproduce this bug:
1. use gdb to attach libvirtd, and set a breakpoint in the function
   qemuMonitorSetCapabilities()
2. start a vm
3. let the libvirtd to run until qemuMonitorJSONSetCapabilities() returns.
4. kill the qemu process
5. continue running libvirtd

Signed-off-by: Wen Congyang <wency cn fujitsu com>

---
 src/qemu/qemu_monitor.c      |    9 ++++++++-
 src/qemu/qemu_monitor_json.c |    9 ++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index eed83f4..647e2bb 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -906,7 +906,14 @@ int qemuMonitorSetCapabilities(qemuMonitorPtr mon)
 
     if (mon->json) {
         ret = qemuMonitorJSONSetCapabilities(mon);
-        mon->json_hmp = qemuMonitorJSONCheckHMP(mon);
+        if (ret == 0) {
+            mon->json_hmp = qemuMonitorJSONCheckHMP(mon);
+            if (mon->json_hmp < 0) {
+                /* qemu may quited unexpectedly when we call
+                 * qemuMonitorJSONCheckHMP() */
+                ret = -1;
+            }
+        }
     } else {
         ret = 0;
     }
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 6bd03d6..20a78e1 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -746,10 +746,14 @@ qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon)
 }
 
 
+/*
+ * Returns: 0 if human-monitor-command is not supported, +1 if
+ * human-monitor-command worked or -1 on failure
+ */
 int
 qemuMonitorJSONCheckHMP(qemuMonitorPtr mon)
 {
-    int ret = 0;
+    int ret = -1;
     virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-commands", NULL);
     virJSONValuePtr reply = NULL;
     virJSONValuePtr data;
@@ -781,6 +785,9 @@ qemuMonitorJSONCheckHMP(qemuMonitorPtr mon)
         }
     }
 
+    /* human-monitor-command is not supported */
+    ret = 0;
+
 cleanup:
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
-- 
1.7.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]