[lxc-devel] [PATCH] cgmanager: also handle named subsystems (like name=systemd)
Stéphane Graber
stgraber at ubuntu.com
Wed May 7 03:49:33 UTC 2014
On Fri, May 02, 2014 at 01:36:32PM -0500, Serge Hallyn wrote:
> 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>
Acked-by: Stéphane Graber <stgraber 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
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140506/217d377b/attachment.sig>
More information about the lxc-devel
mailing list