Users qemuProcessQMP struct were always forced to call both qemuProcessQMPStop and qemuProcessQMPFree when they are done with the process. We can just call qemuProcessQMPStop from qemuProcessQMPFree and let users call qemuProcessQMPFree only. Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> --- Notes: Version 7: - new patch src/qemu/qemu_capabilities.c | 1 - src/qemu/qemu_process.c | 92 ++++++++++++++++++------------------ src/qemu/qemu_process.h | 2 - 3 files changed, 45 insertions(+), 50 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 4fd2169d49..a546d9b5a1 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4397,7 +4397,6 @@ virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps, if (ret < 0) virQEMUCapsLogProbeFailure(qemuCaps->binary); - qemuProcessQMPStop(proc); qemuProcessQMPFree(proc); return ret; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b5d127b7d3..ca5911bacd 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8324,6 +8324,49 @@ static qemuMonitorCallbacks callbacks = { }; +static void +qemuProcessQMPStop(qemuProcessQMPPtr proc) +{ + if (proc->mon) { + virObjectUnlock(proc->mon); + qemuMonitorClose(proc->mon); + proc->mon = NULL; + } + + if (proc->cmd) { + virCommandAbort(proc->cmd); + virCommandFree(proc->cmd); + proc->cmd = NULL; + } + + if (proc->monpath) + unlink(proc->monpath); + + virDomainObjEndAPI(&proc->vm); + + if (proc->pid != 0) { + char ebuf[1024]; + + VIR_DEBUG("Killing QMP caps process %lld", (long long)proc->pid); + if (virProcessKill(proc->pid, SIGKILL) < 0 && errno != ESRCH) + VIR_ERROR(_("Failed to kill process %lld: %s"), + (long long)proc->pid, + virStrerror(errno, ebuf, sizeof(ebuf))); + + proc->pid = 0; + } + + if (proc->pidfile) + unlink(proc->pidfile); +} + + +/** + * qemuProcessQMPFree: + * @proc: Stores process and connection state + * + * Kill QEMU process and free process data structure. + */ void qemuProcessQMPFree(qemuProcessQMPPtr proc) { @@ -8535,7 +8578,6 @@ qemuProcessQMPConnectMonitor(qemuProcessQMPPtr proc) * proc = qemuProcessQMPNew(binary, libDir, runUid, runGid, forceTCG); * qemuProcessQMPStart(proc); * ** Send QMP Queries to QEMU using monitor (proc->mon) ** - * qemuProcessQMPStop(proc); * qemuProcessQMPFree(proc); * * Process error output (proc->stderr) remains available in qemuProcessQMP @@ -8552,57 +8594,13 @@ qemuProcessQMPStart(qemuProcessQMPPtr proc) goto cleanup; if (qemuProcessQMPLaunch(proc) < 0) - goto stop; + goto cleanup; if (qemuProcessQMPConnectMonitor(proc) < 0) - goto stop; + goto cleanup; ret = 0; cleanup: return ret; - - stop: - qemuProcessQMPStop(proc); - goto cleanup; -} - - -void -qemuProcessQMPStop(qemuProcessQMPPtr proc) -{ - if (!proc) - return; - - if (proc->mon) { - virObjectUnlock(proc->mon); - qemuMonitorClose(proc->mon); - proc->mon = NULL; - } - - if (proc->cmd) { - virCommandAbort(proc->cmd); - virCommandFree(proc->cmd); - proc->cmd = NULL; - } - - if (proc->monpath) - unlink(proc->monpath); - - virDomainObjEndAPI(&proc->vm); - - if (proc->pid != 0) { - char ebuf[1024]; - - VIR_DEBUG("Killing QMP caps process %lld", (long long)proc->pid); - if (virProcessKill(proc->pid, SIGKILL) < 0 && errno != ESRCH) - VIR_ERROR(_("Failed to kill process %lld: %s"), - (long long)proc->pid, - virStrerror(errno, ebuf, sizeof(ebuf))); - - proc->pid = 0; - } - - if (proc->pidfile) - unlink(proc->pidfile); } diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 2422d1eb7c..c435a19726 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -242,6 +242,4 @@ void qemuProcessQMPFree(qemuProcessQMPPtr proc); int qemuProcessQMPStart(qemuProcessQMPPtr proc); -void qemuProcessQMPStop(qemuProcessQMPPtr proc); - #endif /* LIBVIRT_QEMU_PROCESS_H */ -- 2.20.1