qemu_capabilities: Stop QEMU process before freeing

virQEMUCapsInitQMP now stops QEMU process in all execution paths,
before freeing the process structure.

The qemuProcessQMPStop function can be called multiple times without
problems... Won't attempt to stop processes and free resources multiple
times.

Follow the convention established in qemu_process of
1) alloc process structure
2) start process
3) use process
4) stop process
5) free process data structure

The process data structure persists after the process activation fails
or the process dies or is killed so stderr strings can be retrieved
until the process data structure is freed.

Signed-off-by: Chris Venteicher <cventeic@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Chris Venteicher 2019-01-12 18:50:05 -06:00 committed by Jiri Denemark
parent 468841eabd
commit bfff747313
2 changed files with 17 additions and 8 deletions

View File

@ -4393,6 +4393,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
ret = 0; ret = 0;
cleanup: cleanup:
qemuProcessQMPStop(proc);
qemuProcessQMPFree(proc); qemuProcessQMPFree(proc);
return ret; return ret;
} }

View File

@ -8488,14 +8488,20 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc,
void void
qemuProcessQMPStop(qemuProcessQMPPtr proc) qemuProcessQMPStop(qemuProcessQMPPtr proc)
{ {
if (proc->mon) if (!proc)
return;
if (proc->mon) {
virObjectUnlock(proc->mon); virObjectUnlock(proc->mon);
qemuMonitorClose(proc->mon); qemuMonitorClose(proc->mon);
proc->mon = NULL; proc->mon = NULL;
}
if (proc->cmd) {
virCommandAbort(proc->cmd); virCommandAbort(proc->cmd);
virCommandFree(proc->cmd); virCommandFree(proc->cmd);
proc->cmd = NULL; proc->cmd = NULL;
}
if (proc->monpath) if (proc->monpath)
unlink(proc->monpath); unlink(proc->monpath);
@ -8512,8 +8518,10 @@ qemuProcessQMPStop(qemuProcessQMPPtr proc)
virStrerror(errno, ebuf, sizeof(ebuf))); virStrerror(errno, ebuf, sizeof(ebuf)));
VIR_FREE(*proc->qmperr); VIR_FREE(*proc->qmperr);
proc->pid = 0;
} }
if (proc->pidfile) if (proc->pidfile)
unlink(proc->pidfile); unlink(proc->pidfile);
proc->pid = 0;
} }