Commit 6203de18 by Daniel Lezcano

rename the ns_cgroup with the container name

It is not easy to follow the cgroup name associated with a container, so right after the container is created, I rename the cgroup which is the pid of the creator by the container name. Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent 920dfa34
......@@ -70,7 +70,24 @@ out:
return err;
}
int lxc_link_nsgroup(const char *name, pid_t pid)
int lxc_rename_nsgroup(const char *name, pid_t pid)
{
char oldname[MAXPATHLEN];
char newname[MAXPATHLEN];
char cgroup[MAXPATHLEN];
if (get_cgroup_mount(MTAB, cgroup)) {
INFO("cgroup is not mounted");
return -1;
}
snprintf(oldname, MAXPATHLEN, "%s/%d", cgroup, pid);
snprintf(newname, MAXPATHLEN, "%s/%s", cgroup, name);
return rename(oldname, newname);
}
int lxc_link_nsgroup(const char *name)
{
char lxc[MAXPATHLEN];
char nsgroup[MAXPATHLEN];
......@@ -83,7 +100,7 @@ int lxc_link_nsgroup(const char *name, pid_t pid)
}
snprintf(lxc, MAXPATHLEN, LXCPATH "/%s/nsgroup", name);
snprintf(nsgroup, MAXPATHLEN, "%s/%d", cgroup, pid);
snprintf(nsgroup, MAXPATHLEN, "%s/%s", cgroup, name);
unlink(lxc);
ret = symlink(nsgroup, lxc);
......
......@@ -26,7 +26,8 @@
#define MAXPRIOLEN 24
int lxc_get_cgroup_mount(const char *mtab, char *mnt);
int lxc_link_nsgroup(const char *name, pid_t pid);
int lxc_rename_nsgroup(const char *name, pid_t pid);
int lxc_link_nsgroup(const char *name);
int lxc_unlink_nsgroup(const char *name);
#endif
......@@ -489,11 +489,12 @@ int lxc_spawn(const char *name, struct lxc_handler *handler, char *const argv[])
goto out_abort;
}
if (lxc_link_nsgroup(name, handler->pid))
if (lxc_rename_nsgroup(name, handler->pid) || lxc_link_nsgroup(name))
WARN("cgroupfs not found: cgroup disabled");
/* Create the network configuration */
if (clone_flags & CLONE_NEWNET && conf_create_network(name, handler->pid)) {
if (clone_flags & CLONE_NEWNET &&
conf_create_network(name, handler->pid)) {
ERROR("failed to create the configured network");
goto out_abort;
}
......
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