mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-15 21:57:19 +00:00
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: Serge Hallyn <serge.hallyn@ubuntu.com> Acked-by: Stéphane Graber <stgraber@ubuntu.com>
This commit is contained in:
parent
44a706bdaf
commit
cbf0bae67c
@ -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) {
|
||||||
|
f = fopen_cloexec("/proc/1/cgroup", "r");
|
||||||
|
if (!f)
|
||||||
return false;
|
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;
|
continue;
|
||||||
*tab1 = '\0';
|
slist++;
|
||||||
|
end = strchr(slist, ':');
|
||||||
|
if (!end)
|
||||||
|
continue;
|
||||||
|
*end = '\0';
|
||||||
|
|
||||||
|
for (p = strtok_r(slist, ",", &saveptr);
|
||||||
|
p;
|
||||||
|
p = strtok_r(NULL, ",", &saveptr)) {
|
||||||
tmp = realloc(subsystems, (nr_subsystems+1)*sizeof(char *));
|
tmp = realloc(subsystems, (nr_subsystems+1)*sizeof(char *));
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
goto out_free;
|
goto out_free;
|
||||||
|
|
||||||
subsystems = tmp;
|
subsystems = tmp;
|
||||||
tmp[nr_subsystems] = strdup(line);
|
tmp[nr_subsystems] = strdup(p);
|
||||||
if (!tmp[nr_subsystems])
|
if (!tmp[nr_subsystems])
|
||||||
goto out_free;
|
goto out_free;
|
||||||
nr_subsystems++;
|
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)
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
out_free:
|
out_free:
|
||||||
|
free(line);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
free_subsystems();
|
free_subsystems();
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user