]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: virPidFileForceCleanupPath: add group argument
authorJán Tomko <jtomko@redhat.com>
Wed, 23 Jun 2021 09:34:57 +0000 (11:34 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 5 Aug 2021 09:18:09 +0000 (11:18 +0200)
Add a version of virPidFileForceCleanupPath that takes
a 'group' bool argument and propagate it all the way
down to virProcessKillPainfullyDelay.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/qemu/qemu_process.c
src/util/virpidfile.c
src/util/virpidfile.h
src/util/virprocess.c
src/util/virprocess.h

index ee7fdcfab4199a17db7c4655c47d7fc5d2703fad..aed40977b3339cfafbfd1a932a31f3560245c969 100644 (file)
@@ -3038,6 +3038,7 @@ virPidFileConstructPath;
 virPidFileDelete;
 virPidFileDeletePath;
 virPidFileForceCleanupPath;
+virPidFileForceCleanupPathFull;
 virPidFileRead;
 virPidFileReadIfAlive;
 virPidFileReadPath;
index 521fda57daf4d5feabefada5d955152286a4469d..6ef8ebd83e04b5ca7883e5beae6d9feca003a586 100644 (file)
@@ -7700,7 +7700,8 @@ qemuProcessKill(virDomainObj *vm, unsigned int flags)
      * to be safe against stalls by the kernel freeing up the resources */
     return virProcessKillPainfullyDelay(vm->pid,
                                         !!(flags & VIR_QEMU_PROCESS_KILL_FORCE),
-                                        vm->def->nhostdevs * 2);
+                                        vm->def->nhostdevs * 2,
+                                        false);
 }
 
 
index c6389c1869c492f1dd539642acf848cab2f79968..7069f8343dc785291f795bb18e0420c4b306d567 100644 (file)
@@ -514,7 +514,7 @@ virPidFileConstructPath(bool privileged,
  * Returns 0 if the pidfile was successfully cleaned up, -1 otherwise.
  */
 int
-virPidFileForceCleanupPath(const char *path)
+virPidFileForceCleanupPathFull(const char *path, bool group)
 {
     pid_t pid = 0;
     int fd = -1;
@@ -529,10 +529,15 @@ virPidFileForceCleanupPath(const char *path)
     if (fd < 0) {
         virResetLastError();
 
+        if (pid > 1 && group)
+            pid = virProcessGroupGet(pid);
+
         /* Only kill the process if the pid is valid one.  0 means
          * there is somebody else doing the same pidfile cleanup
          * machinery. */
-        if (pid)
+        if (group)
+            virProcessKillPainfullyDelay(pid, true, 0, true);
+        else if (pid)
             virProcessKillPainfully(pid, true);
 
         if (virPidFileDeletePath(path) < 0)
@@ -544,3 +549,9 @@ virPidFileForceCleanupPath(const char *path)
 
     return 0;
 }
+
+int
+virPidFileForceCleanupPath(const char *path)
+{
+    return virPidFileForceCleanupPathFull(path, false);
+}
index 370a59892ed71a1d983fa3f9947eaf4036bdc50b..fd8013c41e05b0b23768483527db5232e9f80d19 100644 (file)
@@ -73,4 +73,6 @@ int virPidFileConstructPath(bool privileged,
                             const char *progname,
                             char **pidfile);
 
+int virPidFileForceCleanupPathFull(const char *path,
+                                   bool group) ATTRIBUTE_NONNULL(1);
 int virPidFileForceCleanupPath(const char *path) ATTRIBUTE_NONNULL(1);
index 1bc840120a5f915164a7eac7817259c3e71d0e78..0b5752293624468077ef7f906a7c7533276869c9 100644 (file)
@@ -406,15 +406,15 @@ pid_t virProcessGroupGet(pid_t pid)
  * wait longer than the default.
  */
 int
-virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
+virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay, bool group)
 {
     size_t i;
     /* This is in 1/5th seconds since polling is on a 0.2s interval */
     unsigned int polldelay = (force ? 200 : 75) + (extradelay*5);
     const char *signame = "TERM";
 
-    VIR_DEBUG("vpid=%lld force=%d extradelay=%u",
-              (long long)pid, force, extradelay);
+    VIR_DEBUG("vpid=%lld force=%d extradelay=%u group=%d",
+              (long long)pid, force, extradelay, group);
 
     /* This loop sends SIGTERM, then waits a few iterations (10 seconds)
      * to see if it dies. If the process still hasn't exited, and
@@ -429,6 +429,8 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
      */
     for (i = 0; i < polldelay; i++) {
         int signum;
+        int rc;
+
         if (i == 0) {
             signum = SIGTERM; /* kindly suggest it should exit */
         } else if (i == 50 && force) {
@@ -447,7 +449,12 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
             signum = 0; /* Just check for existence */
         }
 
-        if (virProcessKill(pid, signum) < 0) {
+        if (group)
+            rc = virProcessGroupKill(pid, signum);
+        else
+            rc = virProcessKill(pid, signum);
+
+        if (rc < 0) {
             if (errno != ESRCH) {
                 virReportSystemError(errno,
                                      _("Failed to terminate process %lld with SIG%s"),
@@ -470,7 +477,7 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
 
 int virProcessKillPainfully(pid_t pid, bool force)
 {
-    return virProcessKillPainfullyDelay(pid, force, 0);
+    return virProcessKillPainfullyDelay(pid, force, 0, false);
 }
 
 #if WITH_SCHED_GETAFFINITY
index 9d7c0f479a17af060a1a428653cd43f194038fc6..9910331a0caa5407bdf92ad86cd5aaa89c701e53 100644 (file)
@@ -58,7 +58,8 @@ pid_t virProcessGroupGet(pid_t pid);
 int virProcessKillPainfully(pid_t pid, bool force);
 int virProcessKillPainfullyDelay(pid_t pid,
                                  bool force,
-                                 unsigned int extradelay);
+                                 unsigned int extradelay,
+                                 bool group);
 
 int virProcessSetAffinity(pid_t pid, virBitmap *map, bool quiet);