Gracefully handle case when proc activation failed prior to calling.
Consistent with the existing code for qemuConnectMonitor (for domains)
in qemu_process.c...
- Handle qemMonitorOpen failure with INFO message and NULL ptr
- Identify parameters passed to qemuMonitorOpen
Monitor callbacks will be removed in future patch so we prep for passing
NULL for the callback pointer.
Set proc->mon to NULL then use VIR_STEAL_PTR if successful to be
consistent with other functions.
Signed-off-by: Chris Venteicher <cventeic(a)redhat.com>
---
src/qemu/qemu_process.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 8906a22e3c..31d41688fe 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8262,25 +8262,50 @@ static int
qemuProcessQmpConnectMonitor(qemuProcessQmpPtr proc)
{
int ret = -1;
+ qemuMonitorPtr mon = NULL;
+ unsigned long long timeout = 0;
+ bool retry = true;
+ bool enableJson = true;
+ virQEMUDriverPtr driver = NULL;
+ qemuMonitorCallbacksPtr monCallbacks = &callbacks;
virDomainXMLOptionPtr xmlopt = NULL;
virDomainChrSourceDef monConfig;
VIR_DEBUG("proc=%p, emulator=%s, proc->pid=%lld",
proc, NULLSTR(proc->binary), (long long)proc->pid);
+ if (!proc || !proc->pid) {
+ ret = 0;
+ goto cleanup;
+ }
+
+ proc->mon = NULL;
+
monConfig.type = VIR_DOMAIN_CHR_TYPE_UNIX;
monConfig.data.nix.path = proc->monpath;
monConfig.data.nix.listen = false;
+ /* Create a NULL Domain object for qemuMonitor */
if (!(xmlopt = virDomainXMLOptionNew(NULL, NULL, NULL, NULL, NULL)) ||
!(proc->vm = virDomainObjNew(xmlopt)))
goto cleanup;
proc->vm->pid = proc->pid;
- if (!(proc->mon = qemuMonitorOpen(proc->vm, &monConfig, true, true,
- 0, &callbacks, NULL)))
+ mon = qemuMonitorOpen(proc->vm,
+ &monConfig,
+ enableJson,
+ retry,
+ timeout,
+ monCallbacks,
+ driver);
+
+ if (!mon) {
+ VIR_INFO("Failed to connect monitor to emulator %s", proc->binary);
goto cleanup;
+ }
+
+ VIR_STEAL_PTR(proc->mon, mon);
virObjectLock(proc->mon);
--
2.17.1