]> xenbits.xensource.com Git - people/dariof/libvirt.git/commitdiff
Cope with races while killing processes
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 26 Jul 2013 15:02:22 +0000 (16:02 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 31 Jul 2013 18:27:28 +0000 (19:27 +0100)
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@redhat.com>
src/util/vircgroup.c

index 0e8bb795764507538e3062bd11fd7806a3a05970..a70bb98a8157c498014a9c7e6a5bc1377ed2ef0b 100644 (file)
@@ -2550,6 +2550,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);
@@ -2589,6 +2595,7 @@ static int virCgroupKillInternal(virCgroupPtr group, int signum, virHashTablePtr
         }
     }
 
+ done:
     ret = killedAny ? 1 : 0;
 
 cleanup:
@@ -2658,8 +2665,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;
@@ -2689,6 +2701,7 @@ static int virCgroupKillRecursiveInternal(virCgroupPtr group, int signum, virHas
         virCgroupFree(&subgroup);
     }
 
+ done:
     ret = killedAny ? 1 : 0;
 
 cleanup: