[PATCH] qemu: use a fixed directory for saving qmp capabilities process

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

 



>From c7ee36417b88df7dcfe5e18d1eb72b6d7c175268 Mon Sep 17 00:00:00 2001
From: Bihong Yu <yubihong@xxxxxxxxxx>
Date: Tue, 14 Jul 2020 11:17:46 +0800
Subject: [PATCH] qemu: use a fixed directory for saving qmp capabilities
 process

In some case, the qmp capabilities process possible residues. So we need to
cleanup the residual process during start libvirt. For this reason, we
should use a fixed directory for saving qmp capabilities process.

Change-Id: I6a74a046e192eee169a0e2677ce3aed9ded5e0ed
Signed-off-by:Bihong Yu <yubihong@xxxxxxxxxx>
---
 src/qemu/qemu_process.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 70fc24b..eba14ed 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -8450,21 +8450,24 @@ static int
 qemuProcessQMPInit(qemuProcessQMPPtr proc)
 {
     g_autofree char *template = NULL;
+    virErrorPtr orig_err;

     VIR_DEBUG("proc=%p, emulator=%s", proc, proc->binary);

-    template = g_strdup_printf("%s/qmp-XXXXXX", proc->libDir);
+    template = g_strdup_printf("%s/qmp-capabilities", proc->libDir);

-    if (!(proc->uniqDir = g_mkdtemp(template))) {
+    if (g_mkdir_with_parents(template, 0700) < 0) {
         virReportSystemError(errno,
                              _("Failed to create unique directory with "
                                "template '%s' for probing QEMU"),
                              template);
         return -1;
     }
-    /* if g_mkdtemp succeeds, proc->uniqDir is now the owner of
-     * the string. Set template to NULL to avoid freeing
-     * the memory in this case */
+    /*
+     * if g_mkdir_with_parents succeeds, assign the template to proc->uniqDir.
+     * Then set template to NULL to avoid freeing the memory in this case.
+     */
+    proc->uniqDir = template;
     template = NULL;

     if (qemuProcessQEMULabelUniqPath(proc) < 0)
@@ -8481,6 +8484,10 @@ qemuProcessQMPInit(qemuProcessQMPPtr proc)
      */
     proc->pidfile = g_strdup_printf("%s/%s", proc->uniqDir, "qmp.pid");

+    virErrorPreserveLast(&orig_err);
+    if (virPidFileForceCleanupPath(proc->pidfile) < 0)
+        VIR_WARN("Unable to kill qemu QMP process");
+    virErrorRestore(&orig_err);
     return 0;
 }

-- 
1.8.3.1




[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