]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vircgroup: cleanup controllers not managed by systemd on error
authorPavel Hrdina <phrdina@redhat.com>
Mon, 10 Sep 2018 12:46:24 +0000 (14:46 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 25 Sep 2018 07:59:23 +0000 (09:59 +0200)
If virCgroupEnableMissingControllers() fails it could have already
created some directories, we should clean it up as well.

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/util/vircgroup.c

index e6af38909d9d61f7877d7e1aa7e43fe8bbafe1b6..ec411a7b2b12951ac41ff3f8ccfeae19b755b5f8 100644 (file)
@@ -1551,6 +1551,7 @@ virCgroupNewMachineSystemd(const char *name,
     int rv;
     virCgroupPtr init;
     VIR_AUTOFREE(char *) path = NULL;
+    virErrorPtr saved = NULL;
 
     VIR_DEBUG("Trying to setup machine '%s' via systemd", name);
     if ((rv = virSystemdCreateMachine(name,
@@ -1584,20 +1585,24 @@ virCgroupNewMachineSystemd(const char *name,
 
     if (virCgroupEnableMissingControllers(path, pidleader,
                                           controllers, group) < 0) {
-        return -1;
+        goto error;
     }
 
-    if (virCgroupAddTask(*group, pidleader) < 0) {
-        virErrorPtr saved = virSaveLastError();
-        virCgroupRemove(*group);
-        virCgroupFree(group);
-        if (saved) {
-            virSetError(saved);
-            virFreeError(saved);
-        }
-    }
+    if (virCgroupAddTask(*group, pidleader) < 0)
+        goto error;
 
     return 0;
+
+ error:
+    saved = virSaveLastError();
+    virCgroupRemove(*group);
+    virCgroupFree(group);
+    if (saved) {
+        virSetError(saved);
+        virFreeError(saved);
+    }
+
+    return -1;
 }