From: Daniel Lezcano Date: Thu, 28 May 2009 10:10:50 +0000 (+0200) Subject: rename the ns_cgroup with the container name X-Git-Tag: lxc_0_6_3~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6203de18eb7d623692080a71622547ee0dc9da41;p=thirdparty%2Flxc.git 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: Daniel Lezcano --- diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c index 7827b70c9..75d1a5301 100644 --- a/src/lxc/cgroup.c +++ b/src/lxc/cgroup.c @@ -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); diff --git a/src/lxc/cgroup.h b/src/lxc/cgroup.h index 36029a2aa..ad9802ec2 100644 --- a/src/lxc/cgroup.h +++ b/src/lxc/cgroup.h @@ -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 diff --git a/src/lxc/start.c b/src/lxc/start.c index 392cdd1b2..c3340bb22 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -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; }