[lxc-devel] [PATCH] cgmanager: also handle named subsystems (like name=systemd)
Serge Hallyn
serge.hallyn at ubuntu.com
Fri May 2 18:36:32 UTC 2014
Read /proc/self/cgroup instead of /proc/cgroups, so as to catch
named subsystems. Otherwise the contaienrs will not be fully
moved into the container cgroups.
Also free line which was being leaked.
Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
src/lxc/cgmanager.c | 51 +++++++++++++++++++++++++++++++++------------------
1 file changed, 33 insertions(+), 18 deletions(-)
diff --git a/src/lxc/cgmanager.c b/src/lxc/cgmanager.c
index fc959ec..ab061e4 100644
--- a/src/lxc/cgmanager.c
+++ b/src/lxc/cgmanager.c
@@ -758,39 +758,53 @@ static void free_subsystems(void)
static bool collect_subsytems(void)
{
- char *line = NULL, *tab1;
+ char *line = NULL;
size_t sz = 0;
FILE *f;
if (subsystems) // already initialized
return true;
- f = fopen_cloexec("/proc/cgroups", "r");
+ f = fopen_cloexec("/proc/self/cgroup", "r");
if (!f) {
- return false;
+ f = fopen_cloexec("/proc/1/cgroup", "r");
+ if (!f)
+ return false;
}
while (getline(&line, &sz, f) != -1) {
- char **tmp;
- if (line[0] == '#')
- continue;
+ /* file format: hierarchy:subsystems:group,
+ * with multiple subsystems being ,-separated */
+ char *slist, *end, *p, *saveptr = NULL, **tmp;
+
if (!line[0])
continue;
- tab1 = strchr(line, '\t');
- if (!tab1)
+
+ slist = strchr(line, ':');
+ if (!slist)
+ continue;
+ slist++;
+ end = strchr(slist, ':');
+ if (!end)
continue;
- *tab1 = '\0';
- tmp = realloc(subsystems, (nr_subsystems+1)*sizeof(char *));
- if (!tmp)
- goto out_free;
-
- subsystems = tmp;
- tmp[nr_subsystems] = strdup(line);
- if (!tmp[nr_subsystems])
- goto out_free;
- nr_subsystems++;
+ *end = '\0';
+
+ for (p = strtok_r(slist, ",", &saveptr);
+ p;
+ p = strtok_r(NULL, ",", &saveptr)) {
+ tmp = realloc(subsystems, (nr_subsystems+1)*sizeof(char *));
+ if (!tmp)
+ goto out_free;
+
+ subsystems = tmp;
+ tmp[nr_subsystems] = strdup(p);
+ if (!tmp[nr_subsystems])
+ goto out_free;
+ nr_subsystems++;
+ }
}
fclose(f);
+ free(line);
if (!nr_subsystems) {
ERROR("No cgroup subsystems found");
return false;
@@ -799,6 +813,7 @@ static bool collect_subsytems(void)
return true;
out_free:
+ free(line);
fclose(f);
free_subsystems();
return false;
--
1.9.1
More information about the lxc-devel
mailing list