]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroup: minor bugfixes so start and attach work again
authorChristian Seiler <christian@iwakd.de>
Sun, 18 Aug 2013 22:52:40 +0000 (00:52 +0200)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 19 Aug 2013 16:42:08 +0000 (11:42 -0500)
This fixes some minor bugs in the cgroup logic that made start and
attach fail (at least when all cgroup controllers were mounted
together).

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/cgroup.c
src/lxc/commands.c

index 0d2b81ca61823fedf936466fbfa05edd1ed9809c..12787a33260d8bf0dfba35d69d6e5a93ab75f4d8 100644 (file)
@@ -561,6 +561,26 @@ static int in_subsys_list(const char *s, const char *list)
        return 0;
 }
 
+static int subsys_lists_match(const char *list1, const char *list2)
+{
+       char *token, *str, *saveptr = NULL;
+
+       if (!list1 || !list2)
+               return 0;
+
+        if (strlen(list1) != strlen(list2))
+                return 0;
+
+       str = alloca(strlen(list1)+1);
+       strcpy(str, list1);
+       for (; (token = strtok_r(str, ",", &saveptr)); str = NULL) {
+               if (in_subsys_list(token, list2) == 0)
+                       return 0;
+       }
+
+       return 1;
+}
+
 static void set_clone_children(struct mntent *m)
 {
        char path[MAXPATHLEN];
@@ -626,6 +646,7 @@ static char *record_visited(char *opts, char *all_subsystems)
                else
                        *visited = '\0';
                strcat(visited, token);
+               oldlen += toklen + (oldlen ? 1 : 0);
        }
 
        return visited;
@@ -774,9 +795,12 @@ static bool find_real_cgroup(struct cgroup_desc *d, char *path)
                if (!(p2 = index(++p, ':')))
                        continue;
                *p2 = '\0';
+               // remove trailing newlines
+               if (*(p2 + 1) && p2[strlen(p2 + 1)] == '\n')
+                       p2[strlen(p2 + 1)] = '\0';
                // in case of multiple mounts it may be more correct to
                // insist all subsystems be the same
-               if (in_subsys_list(p, d->subsystems))
+               if (subsys_lists_match(p, d->subsystems))
                        goto found;
        }
 
@@ -1134,7 +1158,7 @@ void lxc_cgroup_destroy_desc(struct cgroup_desc *cgroups)
 int lxc_cgroup_attach(pid_t pid, const char *name, const char *lxcpath)
 {
        FILE *f;
-       char *line = NULL, ret = -1;
+       char *line = NULL, ret = 0;
        size_t len = 0;
        int first = 1;
        char *dirpath;
@@ -1162,8 +1186,9 @@ int lxc_cgroup_attach(pid_t pid, const char *name, const char *lxcpath)
                        continue;
 
                INFO("joining pid %d to cgroup %s", pid, dirpath);
-               if (lxc_cgroup_enter_one(dirpath, pid)) {
+               if (!lxc_cgroup_enter_one(dirpath, pid)) {
                        ERROR("Failed joining %d to %s\n", pid, dirpath);
+                       ret = -1;
                        continue;
                }
        }
index f1f9fcc717e709072ca39ff823e9fd471c15b1fe..a7981ba606207fb98a2202933cd9514f192f74f8 100644 (file)
@@ -393,12 +393,13 @@ static int lxc_cmd_get_cgroup_callback(int fd, struct lxc_cmd_req *req,
 
        if (req->datalen < 1)
                return -1;
-
+        
        path = cgroup_get_subsys_path(handler, req->data);
        if (!path)
                return -1;
        rsp.datalen = strlen(path) + 1,
        rsp.data = path;
+       rsp.ret = 0;
 
        return lxc_cmd_rsp_send(fd, &rsp);
 }