[libvirt PATCH 2/2] util: fix success return for virProcessKillPainfullyDelay()

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

 



virProcessKillPainfullyDelay() currently almost always returns 1 or -1,
even though the documentation indicates that it should return 0 if the
process was terminated gracefully. The only case that it currently
returns 0 is when it is called with the pid of a process that does not
exist.

This function initially sends a SIGTERM signal to the process. If
the signal was sent successfully (i.e. virProcessKill() returns 0) we
immediately sleep for 200ms before iterating the loop. On the second
iteration of the loop, signum will be set to 0 and we call
virProcessKill() again to check whether the process still exists. If the
process does not exist (virProcessKill() returns -1 and errno is ESRCH),
we consider the process killed successfully. But in order to determine
what value to return from the function, we compare the value of signum
to SIGTERM. But signum has already been set to 0; it will only ever be
SIGTERM in the very first loop iteration. So it always indicates a
forcible killing even when it is killed gracefully.

Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
---
 src/util/virprocess.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 6ce5ef99a9..42b3b76eaa 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -377,6 +377,7 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay, boo
     /* 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";
+    int forced = 0;
 
     VIR_DEBUG("vpid=%lld force=%d extradelay=%u group=%d",
               (long long)pid, force, extradelay, group);
@@ -399,6 +400,7 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay, boo
         if (i == 0) {
             signum = SIGTERM; /* kindly suggest it should exit */
         } else if (i == 50 && force) {
+            forced = 1;
             VIR_DEBUG("Timed out waiting after SIGTERM to process %lld, "
                       "sending SIGKILL", (long long)pid);
             /* No SIGKILL kill on Win32 ! Use SIGABRT instead which our
@@ -426,7 +428,7 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay, boo
                                      (long long)pid, signame);
                 return -1;
             }
-            return signum == SIGTERM ? 0 : 1;
+            return forced;
         }
 
         g_usleep(200 * 1000);
-- 
2.41.0




[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