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

[libvirt] [PATCH 02/20] Wait to receive QMP greeting before sending any monitor commands



From: "Daniel P. Berrange" <berrange redhat com>

Technically speaking we should wait until we receive the QMP
greeting message before attempting to send any QMP monitor
commands. Mostly we've got away with this, but there is a race
in some QEMU which cause it to SEGV if you sent it data too
soon after startup. Waiting for the QMP greeting avoids the
race

Signed-off-by: Daniel P. Berrange <berrange redhat com>
---
 src/qemu/qemu_monitor.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 290f150..fb67b9a 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -79,6 +79,7 @@ struct _qemuMonitor {
 
     unsigned json: 1;
     unsigned json_hmp: 1;
+    unsigned wait_greeting: 1;
 };
 
 static virClassPtr qemuMonitorClass;
@@ -365,6 +366,9 @@ qemuMonitorIOProcess(qemuMonitorPtr mon)
     if (len < 0)
         return -1;
 
+    if (len && mon->wait_greeting)
+        mon->wait_greeting = 0;
+
     if (len < mon->bufferOffset) {
         memmove(mon->buffer, mon->buffer + len, mon->bufferOffset - len);
         mon->bufferOffset -= len;
@@ -538,7 +542,8 @@ static void qemuMonitorUpdateWatch(qemuMonitorPtr mon)
     if (mon->lastError.code == VIR_ERR_OK) {
         events |= VIR_EVENT_HANDLE_READABLE;
 
-        if (mon->msg && mon->msg->txOffset < mon->msg->txLength)
+        if ((mon->msg && mon->msg->txOffset < mon->msg->txLength) &&
+            !mon->wait_greeting)
             events |= VIR_EVENT_HANDLE_WRITABLE;
     }
 
@@ -716,6 +721,8 @@ qemuMonitorOpen(virDomainObjPtr vm,
     mon->fd = -1;
     mon->vm = vm;
     mon->json = json;
+    if (json)
+        mon->wait_greeting = 1;
     mon->cb = cb;
     qemuMonitorLock(mon);
 
-- 
1.7.11.4


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