From: Daniel Lezcano Date: Thu, 16 Jul 2009 14:38:15 +0000 (+0200) Subject: Remove the a previous cgroup X-Git-Tag: lxc_0_6_3~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0dd4566ecadfa4a42529250513dc68b6aed4ce92;p=thirdparty%2Flxc.git Remove the a previous cgroup 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 --- diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c index 26440427a..c2aa691ce 100644 --- a/src/lxc/cgroup.c +++ b/src/lxc/cgroup.c @@ -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);