[PATCH 3/4] Cope with races while killing processes

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

When systemd is involved in managing processes, it may start
killing off & tearing down croups associated with the process
while we're still doing virCgroupKillPainfully. We must
explicitly check for ENOENT and treat it as if we had finished
killing processes

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/util/vircgroup.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 5ff8850..94f6692 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -2539,6 +2539,12 @@ static int virCgroupKillInternal(virCgroupPtr group, int signum, virHashTablePtr
     while (!done) {
         done = true;
         if (!(fp = fopen(keypath, "r"))) {
+            if (errno == ENOENT) {
+                VIR_DEBUG("No file %s, assuming done", keypath);
+                killedAny = false;
+                goto done;
+            }
+
             virReportSystemError(errno,
                                  _("Failed to read %s"),
                                  keypath);
@@ -2578,6 +2584,7 @@ static int virCgroupKillInternal(virCgroupPtr group, int signum, virHashTablePtr
         }
     }
 
+ done:
     ret = killedAny ? 1 : 0;
 
 cleanup:
@@ -2647,8 +2654,13 @@ static int virCgroupKillRecursiveInternal(virCgroupPtr group, int signum, virHas
     if (rc == 1)
         killedAny = true;
 
-    VIR_DEBUG("Iterate over children of %s", keypath);
+    VIR_DEBUG("Iterate over children of %s (killedAny=%d)", keypath, killedAny);
     if (!(dp = opendir(keypath))) {
+        if (errno == ENOENT) {
+            VIR_DEBUG("Path %s does not exist, assuming done", keypath);
+            killedAny = false;
+            goto done;
+        }
         virReportSystemError(errno,
                              _("Cannot open %s"), keypath);
         return -1;
@@ -2678,6 +2690,7 @@ static int virCgroupKillRecursiveInternal(virCgroupPtr group, int signum, virHas
         virCgroupFree(&subgroup);
     }
 
+ done:
     ret = killedAny ? 1 : 0;
 
 cleanup:
-- 
1.8.1.4

--
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]