Commit cbf0bae6 by Serge Hallyn Committed by Stéphane Graber

cgmanager: also handle named subsystems (like name=systemd)

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: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 44a706bd
...@@ -758,39 +758,53 @@ static void free_subsystems(void) ...@@ -758,39 +758,53 @@ static void free_subsystems(void)
static bool collect_subsytems(void) static bool collect_subsytems(void)
{ {
char *line = NULL, *tab1; char *line = NULL;
size_t sz = 0; size_t sz = 0;
FILE *f; FILE *f;
if (subsystems) // already initialized if (subsystems) // already initialized
return true; return true;
f = fopen_cloexec("/proc/cgroups", "r"); f = fopen_cloexec("/proc/self/cgroup", "r");
if (!f) { if (!f) {
return false; f = fopen_cloexec("/proc/1/cgroup", "r");
if (!f)
return false;
} }
while (getline(&line, &sz, f) != -1) { while (getline(&line, &sz, f) != -1) {
char **tmp; /* file format: hierarchy:subsystems:group,
if (line[0] == '#') * with multiple subsystems being ,-separated */
continue; char *slist, *end, *p, *saveptr = NULL, **tmp;
if (!line[0]) if (!line[0])
continue; continue;
tab1 = strchr(line, '\t');
if (!tab1) slist = strchr(line, ':');
if (!slist)
continue;
slist++;
end = strchr(slist, ':');
if (!end)
continue; continue;
*tab1 = '\0'; *end = '\0';
tmp = realloc(subsystems, (nr_subsystems+1)*sizeof(char *));
if (!tmp) for (p = strtok_r(slist, ",", &saveptr);
goto out_free; p;
p = strtok_r(NULL, ",", &saveptr)) {
subsystems = tmp; tmp = realloc(subsystems, (nr_subsystems+1)*sizeof(char *));
tmp[nr_subsystems] = strdup(line); if (!tmp)
if (!tmp[nr_subsystems]) goto out_free;
goto out_free;
nr_subsystems++; subsystems = tmp;
tmp[nr_subsystems] = strdup(p);
if (!tmp[nr_subsystems])
goto out_free;
nr_subsystems++;
}
} }
fclose(f); fclose(f);
free(line);
if (!nr_subsystems) { if (!nr_subsystems) {
ERROR("No cgroup subsystems found"); ERROR("No cgroup subsystems found");
return false; return false;
...@@ -799,6 +813,7 @@ static bool collect_subsytems(void) ...@@ -799,6 +813,7 @@ static bool collect_subsytems(void)
return true; return true;
out_free: out_free:
free(line);
fclose(f); fclose(f);
free_subsystems(); free_subsystems();
return false; return false;
......
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