43fe83
From 1e84e3165f8d37f8eebf862c6811f346cd8dbcca Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <1e84e3165f8d37f8eebf862c6811f346cd8dbcca.1375465853.git.jdenemar@redhat.com>
43fe83
From: "Daniel P. Berrange" <berrange@redhat.com>
43fe83
Date: Wed, 31 Jul 2013 19:48:19 +0100
43fe83
Subject: [PATCH] Cope with races while killing processes
43fe83
43fe83
https://bugzilla.redhat.com/show_bug.cgi?id=980929
43fe83
43fe83
When systemd is involved in managing processes, it may start
43fe83
killing off & tearing down croups associated with the process
43fe83
while we're still doing virCgroupKillPainfully. We must
43fe83
explicitly check for ENOENT and treat it as if we had finished
43fe83
killing processes
43fe83
43fe83
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
43fe83
43fe83
(cherry picked from commit 75304eaa1a08b23e5206b352403de7d296fc069e)
43fe83
---
43fe83
 src/util/vircgroup.c | 15 ++++++++++++++-
43fe83
 1 file changed, 14 insertions(+), 1 deletion(-)
43fe83
43fe83
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
43fe83
index 0e8bb79..a70bb98 100644
43fe83
--- a/src/util/vircgroup.c
43fe83
+++ b/src/util/vircgroup.c
43fe83
@@ -2550,6 +2550,12 @@ static int virCgroupKillInternal(virCgroupPtr group, int signum, virHashTablePtr
43fe83
     while (!done) {
43fe83
         done = true;
43fe83
         if (!(fp = fopen(keypath, "r"))) {
43fe83
+            if (errno == ENOENT) {
43fe83
+                VIR_DEBUG("No file %s, assuming done", keypath);
43fe83
+                killedAny = false;
43fe83
+                goto done;
43fe83
+            }
43fe83
+
43fe83
             virReportSystemError(errno,
43fe83
                                  _("Failed to read %s"),
43fe83
                                  keypath);
43fe83
@@ -2589,6 +2595,7 @@ static int virCgroupKillInternal(virCgroupPtr group, int signum, virHashTablePtr
43fe83
         }
43fe83
     }
43fe83
 
43fe83
+ done:
43fe83
     ret = killedAny ? 1 : 0;
43fe83
 
43fe83
 cleanup:
43fe83
@@ -2658,8 +2665,13 @@ static int virCgroupKillRecursiveInternal(virCgroupPtr group, int signum, virHas
43fe83
     if (rc == 1)
43fe83
         killedAny = true;
43fe83
 
43fe83
-    VIR_DEBUG("Iterate over children of %s", keypath);
43fe83
+    VIR_DEBUG("Iterate over children of %s (killedAny=%d)", keypath, killedAny);
43fe83
     if (!(dp = opendir(keypath))) {
43fe83
+        if (errno == ENOENT) {
43fe83
+            VIR_DEBUG("Path %s does not exist, assuming done", keypath);
43fe83
+            killedAny = false;
43fe83
+            goto done;
43fe83
+        }
43fe83
         virReportSystemError(errno,
43fe83
                              _("Cannot open %s"), keypath);
43fe83
         return -1;
43fe83
@@ -2689,6 +2701,7 @@ static int virCgroupKillRecursiveInternal(virCgroupPtr group, int signum, virHas
43fe83
         virCgroupFree(&subgroup);
43fe83
     }
43fe83
 
43fe83
+ done:
43fe83
     ret = killedAny ? 1 : 0;
43fe83
 
43fe83
 cleanup:
43fe83
-- 
43fe83
1.8.3.2
43fe83