Commit 0dd4566e by Daniel Lezcano

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: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 3a0f472d
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment