[PATCH v6 10/33] qemu_process: Persist stderr in qemuProcessQMP struct

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A qemuProcessQMP struct tracks the entire lifespan of a single QEMU Process
including storing error output when the process terminates or activation
fails.

Error output remains available until qemuProcessQMPFree is called.

The qmperr variable is renamed stderr (captures stderr from process.)

The stderr buffer no longer needs to be maintained outside of the
qemuProcessQMP structure because the structure is used for a single QEMU
process and the structures can be maintained as long as required
to retrieve the process error info.

Signed-off-by: Chris Venteicher <cventeic@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 8 +++-----
 src/qemu/qemu_process.c      | 9 +++------
 src/qemu/qemu_process.h      | 3 +--
 3 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 12c4ed2eb5..b833e0d11e 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4377,18 +4377,17 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
 {
     qemuProcessQMPPtr proc = NULL;
     qemuProcessQMPPtr procTCG = NULL;
-    char *qmperr = NULL;
     int ret = -1;
 
     if (!(proc = qemuProcessQMPNew(qemuCaps->binary, libDir,
-                                   runUid, runGid, &qmperr, false)))
+                                   runUid, runGid, false)))
         goto cleanup;
 
     if (qemuProcessQMPRun(proc) < 0) {
         if (proc->status != 0)
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to probe QEMU binary with QMP: %s"),
-                           qmperr ? qmperr : _("uknown error"));
+                           proc->stderr ? proc->stderr : _("uknown error"));
 
         goto cleanup;
     }
@@ -4404,7 +4403,7 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
         qemuProcessQMPStop(proc);
 
         procTCG = qemuProcessQMPNew(qemuCaps->binary, libDir,
-                                    runUid, runGid, NULL, true);
+                                    runUid, runGid, true);
 
         if (qemuProcessQMPRun(procTCG) < 0)
             goto cleanup;
@@ -4423,7 +4422,6 @@ virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps,
     qemuProcessQMPStop(procTCG);
     qemuProcessQMPFree(proc);
     qemuProcessQMPFree(procTCG);
-    VIR_FREE(qmperr);
 
     return ret;
 }
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 10e7bc5f11..71c7fb58ad 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8214,6 +8214,7 @@ qemuProcessQMPFree(qemuProcessQMPPtr proc)
     VIR_FREE(proc->monpath);
     VIR_FREE(proc->monarg);
     VIR_FREE(proc->pidfile);
+    VIR_FREE(proc->stderr);
     VIR_FREE(proc);
 }
 
@@ -8223,7 +8224,6 @@ qemuProcessQMPNew(const char *binary,
                   const char *libDir,
                   uid_t runUid,
                   gid_t runGid,
-                  char **qmperr,
                   bool forceTCG)
 {
     qemuProcessQMPPtr proc = NULL;
@@ -8236,7 +8236,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
@@ -8308,7 +8307,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc)
     virCommandSetGID(proc->cmd, proc->runGid);
     virCommandSetUID(proc->cmd, proc->runUid);
 
-    virCommandSetErrorBuffer(proc->cmd, proc->qmperr);
+    virCommandSetErrorBuffer(proc->cmd, &(proc->stderr));
 
     proc->status = 0;
 
@@ -8317,7 +8316,7 @@ qemuProcessQMPRun(qemuProcessQMPPtr proc)
 
     if (proc->status != 0) {
         VIR_DEBUG("QEMU %s exited with status %d: %s",
-                  proc->binary, proc->status, *proc->qmperr);
+                  proc->binary, proc->status, proc->stderr);
         goto cleanup;
     }
 
@@ -8381,8 +8380,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 149829df52..b0b58f9424 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -221,7 +221,7 @@ struct _qemuProcessQMP {
     uid_t runUid;
     gid_t runGid;
     int status;
-    char **qmperr;
+    char *stderr;
     char *monarg;
     char *monpath;
     char *pidfile;
@@ -237,7 +237,6 @@ qemuProcessQMPPtr qemuProcessQMPNew(const char *binary,
                                     const char *libDir,
                                     uid_t runUid,
                                     gid_t runGid,
-                                    char **qmperr,
                                     bool forceTCG);
 
 void qemuProcessQMPFree(qemuProcessQMPPtr proc);
-- 
2.17.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux