[libvirt PATCH 1/3] Introduce virPidFileForceCleanupPathDelay

Ján Tomko jtomko at redhat.com
Fri Jun 18 11:45:17 UTC 2021


Add a version of virPidFileForceCleanupPath with an extradelay
parameter for processes where the default timeout is not enough.

Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/libvirt_private.syms |  1 +
 src/util/virpidfile.c    | 16 +++++++++++++++-
 src/util/virpidfile.h    |  2 ++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2efa787664..dc25dd6ac0 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3027,6 +3027,7 @@ virPidFileConstructPath;
 virPidFileDelete;
 virPidFileDeletePath;
 virPidFileForceCleanupPath;
+virPidFileForceCleanupPathDelay;
 virPidFileRead;
 virPidFileReadIfAlive;
 virPidFileReadPath;
diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
index c6389c1869..6c3d869460 100644
--- a/src/util/virpidfile.c
+++ b/src/util/virpidfile.c
@@ -511,10 +511,14 @@ virPidFileConstructPath(bool privileged,
  * called multiple times with the same path, be it in threads or
  * processes.  This function does not raise any errors.
  *
+ * If @extradelay (in seconds) is specified, we wait for
+ * 15 + extradelay seconds more.
+ *
  * Returns 0 if the pidfile was successfully cleaned up, -1 otherwise.
  */
 int
-virPidFileForceCleanupPath(const char *path)
+virPidFileForceCleanupPathDelay(const char *path,
+                                unsigned int extradelay)
 {
     pid_t pid = 0;
     int fd = -1;
@@ -532,6 +536,9 @@ virPidFileForceCleanupPath(const char *path)
         /* Only kill the process if the pid is valid one.  0 means
          * there is somebody else doing the same pidfile cleanup
          * machinery. */
+        if (extradelay &&
+            virProcessKillPainfullyDelay(pid, false, extradelay) >= 0)
+            pid = 0;
         if (pid)
             virProcessKillPainfully(pid, true);
 
@@ -544,3 +551,10 @@ virPidFileForceCleanupPath(const char *path)
 
     return 0;
 }
+
+
+int
+virPidFileForceCleanupPath(const char *path)
+{
+    return virPidFileForceCleanupPathDelay(path, 0);
+}
diff --git a/src/util/virpidfile.h b/src/util/virpidfile.h
index 370a59892e..ef26377375 100644
--- a/src/util/virpidfile.h
+++ b/src/util/virpidfile.h
@@ -73,4 +73,6 @@ int virPidFileConstructPath(bool privileged,
                             const char *progname,
                             char **pidfile);
 
+int virPidFileForceCleanupPathDelay(const char *path,
+                                    unsigned int extradelay) ATTRIBUTE_NONNULL(1);
 int virPidFileForceCleanupPath(const char *path) ATTRIBUTE_NONNULL(1);
-- 
2.31.1




More information about the libvir-list mailing list