]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Remove the a previous cgroup
authorDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 16 Jul 2009 14:38:15 +0000 (16:38 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 16 Jul 2009 14:38:15 +0000 (16:38 +0200)
As a previous run may have created a cgroup but died unexpectedly,
the cgroup can be still there when we try to launch the container
again with the same name. This patch removes the directory if it is
present, if this one is not owned by caller or it is in use (that should
not happen), the rmdir will fail with the corresponding errno.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
src/lxc/cgroup.c

index 26440427a88b42ee07a7d34eba53848a92b9faa2..c2aa691ce3ecf60397faea6aff132314175c695d 100644 (file)
@@ -94,6 +94,17 @@ int lxc_rename_nsgroup(const char *name, pid_t pid)
        snprintf(oldname, MAXPATHLEN, "%s/%d", cgroup, pid);
        snprintf(newname, MAXPATHLEN, "%s/%s", cgroup, name);
 
+       /* there is a previous cgroup, assume it is empty, otherwise
+        * that fails */
+       if (!access(newname, F_OK)) {
+               ret = rmdir(newname);
+               if (ret) {
+                       SYSERROR("failed to remove previous cgroup '%s'",
+                                newname);
+                       return ret;
+               }
+       }
+
        ret = rename(oldname, newname);
        if (ret)
                SYSERROR("failed to rename cgroup %s->%s", oldname, newname);