From e90c93acc08a09e34dab1021a2479358a664438e Mon Sep 17 00:00:00 2001 From: Jan Safranek Date: Fri, 23 Sep 2011 13:52:59 +0200 Subject: [PATCH] libcgroup: the library can be re-initialize by cgroup_init() cgroup_init() can be called several times in sequence. New call completelly rewrites old data, i.e. things that were unmounted between two cgroup_init() calls disappear and new mount points show up. Signed-off-by: Jan Safranek --- src/api.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/api.c b/src/api.c index e2e4189b..5987afc3 100644 --- a/src/api.c +++ b/src/api.c @@ -850,6 +850,17 @@ int cgroup_init(void) pthread_rwlock_wrlock(&cg_mount_table_lock); + /* free global variables filled by previous cgroup_init() */ + for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) { + struct cg_mount_point *mount = cg_mount_table[i].mount.next; + while (mount) { + struct cg_mount_point *tmp = mount; + mount = mount->next; + free(tmp); + } + } + memset(&cg_mount_table, 0, sizeof(cg_mount_table)); + proc_cgroup = fopen("/proc/cgroups", "re"); if (!proc_cgroup) { @@ -878,6 +889,7 @@ int cgroup_init(void) } free(buf); + i = 0; while (!feof(proc_cgroup)) { err = fscanf(proc_cgroup, "%s %d %d %d", subsys_name, &hierarchy, &num_cgroups, &enabled); -- 2.47.2