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 | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 70ca82dd55..af6b20713a 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8236,25 +8236,48 @@ static int
qemuConnectMonitorQmp(qemuProcessPtr 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)
+ goto ignore;
+
+ 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 ignore;
+ }
+
+ VIR_STEAL_PTR(proc->mon, mon);
virObjectLock(proc->mon);
--
2.17.1