]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: agent: take monitor lock in qemuAgentNotifyEvent
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Mon, 12 Dec 2016 09:13:44 +0000 (12:13 +0300)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 12 Dec 2016 22:14:11 +0000 (17:14 -0500)
qemuAgentNotifyEvent accesses monitor structure and is called on qemu
reset/shutdown/suspend events under domain lock. Other monitor
functions on the other hand take monitor lock and don't hold domain lock.
Thus it is possible to have risky simultaneous access to the structure
from 2 threads. Let's take monitor lock here to make access exclusive.

src/qemu/qemu_agent.c

index c50f7604fbc7484a4276af4e249d654b898ef812..46cad5366f3436794452077ccd7f5183a936f5d8 100644 (file)
@@ -1248,6 +1248,8 @@ qemuAgentMakeStringsArray(const char **strings, unsigned int len)
 void qemuAgentNotifyEvent(qemuAgentPtr mon,
                           qemuAgentEvent event)
 {
+    virObjectLock(mon);
+
     VIR_DEBUG("mon=%p event=%d await_event=%d", mon, event, mon->await_event);
     if (mon->await_event == event) {
         mon->await_event = QEMU_AGENT_EVENT_NONE;
@@ -1257,6 +1259,8 @@ void qemuAgentNotifyEvent(qemuAgentPtr mon,
             virCondSignal(&mon->notify);
         }
     }
+
+    virObjectUnlock(mon);
 }
 
 VIR_ENUM_DECL(qemuAgentShutdownMode);