]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
rename the ns_cgroup with the container name
authorDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 28 May 2009 10:10:50 +0000 (12:10 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 28 May 2009 10:10:50 +0000 (12:10 +0200)
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 <dlezcano@fr.ibm.com>
src/lxc/cgroup.c
src/lxc/cgroup.h
src/lxc/start.c

index 7827b70c98d76b59953418e57276a38525ee8947..75d1a5301ac46cffa85409322498bef3827be6b5 100644 (file)
@@ -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);
index 36029a2aad0312c8e2bd797999b45dfcb0089ca3..ad9802ec22e2b7a46b7ac4134adcf0916a7a86c2 100644 (file)
@@ -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
index 392cdd1b2f5ee109b6cc153da6a3f830e7cc5e10..c3340bb22b0321abc336c77a0af70de562aa4647 100644 (file)
@@ -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;
        }