Keep the pointer to QEMU stderr output in qemuProcessQMP struct instead
of requiring the caller to provide it (and free it).
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 7:
- this is a combination of the relevant parts of
[PATCH 09/33] qemu_process: Expose process exit status code
and
[PATCH 10/33] qemu_process: Persist stderr in qemuProcessQMP struct
adapted to the changes made in the previous patches
src/qemu/qemu_capabilities.c | 14 +++++---------
src/qemu/qemu_process.c | 9 +++------
src/qemu/qemu_process.h | 3 +--
3 files changed, 9 insertions(+), 17 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 264dcae983..7460b452a0 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4376,14 +4376,13 @@ virQEMUCapsInitQMPSingle(virQEMUCapsPtr qemuCaps,
const char *libDir,
uid_t runUid,
gid_t runGid,
- char **qmperr,
bool onlyTCG)
{
qemuProcessQMPPtr proc = NULL;
int ret = -1;
if (!(proc = qemuProcessQMPNew(qemuCaps->binary, libDir,
- runUid, runGid, qmperr, onlyTCG)))
+ runUid, runGid, onlyTCG)))
goto cleanup;
if (qemuProcessQMPRun(proc) < 0)
@@ -4408,10 +4407,9 @@ static int
virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
const char *libDir,
uid_t runUid,
- gid_t runGid,
- char **qmperr)
+ gid_t runGid)
{
- if (virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, qmperr, false) <
0)
+ if (virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, false) < 0)
return -1;
/*
@@ -4420,7 +4418,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
* off.
*/
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) &&
- virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, NULL, true) < 0)
+ virQEMUCapsInitQMPSingle(qemuCaps, libDir, runUid, runGid, true) < 0)
return -1;
return 0;
@@ -4438,7 +4436,6 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
{
virQEMUCapsPtr qemuCaps;
struct stat sb;
- char *qmperr = NULL;
if (!(qemuCaps = virQEMUCapsNew()))
goto error;
@@ -4465,7 +4462,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
goto error;
}
- if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid, &qmperr) < 0)
+ if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid) < 0)
goto error;
qemuCaps->libvirtCtime = virGetSelfLastChanged();
@@ -4484,7 +4481,6 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
}
cleanup:
- VIR_FREE(qmperr);
return qemuCaps;
error:
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 728176bbdf..d2859da2ec 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8335,6 +8335,7 @@ qemuProcessQMPFree(qemuProcessQMPPtr proc)
VIR_FREE(proc->monpath);
VIR_FREE(proc->monarg);
VIR_FREE(proc->pidfile);
+ VIR_FREE(proc->stderr);
VIR_FREE(proc);
}
@@ -8344,7 +8345,6 @@ qemuProcessQMPNew(const char *binary,
const char *libDir,
uid_t runUid,
gid_t runGid,
- char **qmperr,
bool forceTCG)
{
qemuProcessQMPPtr proc = NULL;
@@ -8357,7 +8357,6 @@ qemuProcessQMPNew(const char *binary,
proc->runUid = runUid;
proc->runGid = runGid;
- proc->qmperr = qmperr;
proc->forceTCG = forceTCG;
/* the ".sock" sufix is important to avoid a possible clash with a qemu
@@ -8439,7 +8438,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc)
virCommandSetGID(proc->cmd, proc->runGid);
virCommandSetUID(proc->cmd, proc->runUid);
- virCommandSetErrorBuffer(proc->cmd, proc->qmperr);
+ virCommandSetErrorBuffer(proc->cmd, &(proc->stderr));
if (virCommandRun(proc->cmd, &status) < 0)
goto cleanup;
@@ -8449,7 +8448,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to start QEMU binary %s for probing: %s"),
proc->binary,
- *proc->qmperr ? *proc->qmperr : _("unknown
error"));
+ proc->stderr ? proc->stderr : _("unknown
error"));
goto cleanup;
}
@@ -8513,8 +8512,6 @@ qemuProcessQMPStop(qemuProcessQMPPtr proc)
(long long)proc->pid,
virStrerror(errno, ebuf, sizeof(ebuf)));
- VIR_FREE(*proc->qmperr);
-
proc->pid = 0;
}
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 46a0bd2475..e7d4ca0c92 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -220,7 +220,7 @@ struct _qemuProcessQMP {
char *binary;
uid_t runUid;
gid_t runGid;
- char **qmperr;
+ char *stderr;
char *monarg;
char *monpath;
char *pidfile;
@@ -236,7 +236,6 @@ qemuProcessQMPPtr qemuProcessQMPNew(const char *binary,
const char *libDir,
uid_t runUid,
gid_t runGid,
- char **qmperr,
bool forceTCG);
void qemuProcessQMPFree(qemuProcessQMPPtr proc);
--
2.20.1