Implement qemuMonitorRegister() as there is already a qemuMonitorUnregister() function. This way it may be easier to understand the code paths. Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxxxxxxx> Reviewed-by: Bjoern Walk <bwalk@xxxxxxxxxxxxxxxxxx> --- src/qemu/qemu_monitor.c | 38 +++++++++++++++++++++++++++++--------- src/qemu/qemu_monitor.h | 2 ++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index b41aaed..34037ac 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -837,15 +837,7 @@ qemuMonitorOpenInternal(virDomainObjPtr vm, virObjectLock(mon); - virObjectRef(mon); - if ((mon->watch = virEventAddHandle(mon->fd, - VIR_EVENT_HANDLE_HANGUP | - VIR_EVENT_HANDLE_ERROR | - VIR_EVENT_HANDLE_READABLE, - qemuMonitorIO, - mon, - virObjectFreeCallback)) < 0) { - virObjectUnref(mon); + if (!qemuMonitorRegister(mon)) { virObjectUnlock(mon); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to register monitor events")); @@ -944,6 +936,34 @@ qemuMonitorOpenFD(virDomainObjPtr vm, } +/** + * qemuMonitorRegister: + * @mon: QEMU monitor + * + * Registers the monitor in the event loop. The caller has to hold the + * lock for @mon. + * + * Returns true in case of success, false otherwise + */ +bool +qemuMonitorRegister(qemuMonitorPtr mon) +{ + virObjectRef(mon); + if ((mon->watch = virEventAddHandle(mon->fd, + VIR_EVENT_HANDLE_HANGUP | + VIR_EVENT_HANDLE_ERROR | + VIR_EVENT_HANDLE_READABLE, + qemuMonitorIO, + mon, + virObjectFreeCallback)) < 0) { + virObjectUnref(mon); + return false; + } + + return true; +} + + void qemuMonitorUnregister(qemuMonitorPtr mon) { diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 2e42d16..12f98be 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -296,6 +296,8 @@ qemuMonitorPtr qemuMonitorOpenFD(virDomainObjPtr vm, void *opaque) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); +bool qemuMonitorRegister(qemuMonitorPtr mon) + ATTRIBUTE_NONNULL(1); void qemuMonitorUnregister(qemuMonitorPtr mon) ATTRIBUTE_NONNULL(1); void qemuMonitorClose(qemuMonitorPtr mon); -- 2.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list