From: Jan Safranek Date: Fri, 23 Sep 2011 11:52:59 +0000 (+0200) Subject: libcgroup: the library can be re-initialize by cgroup_init() X-Git-Tag: v0.38~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e90c93acc08a09e34dab1021a2479358a664438e;p=thirdparty%2Flibcgroup.git 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 --- 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);