]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: the library can be re-initialize by cgroup_init()
authorJan Safranek <jsafrane@redhat.com>
Fri, 23 Sep 2011 11:52:59 +0000 (13:52 +0200)
committerJan Safranek <jsafrane@redhat.com>
Thu, 3 Nov 2011 09:12:46 +0000 (10:12 +0100)
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 <jsafrane@redhat.com>
src/api.c

index e2e4189b01e83a37a44d8e834637719fec7e4657..5987afc3b98836b7c71b34f3d2efe6552db38206 100644 (file)
--- 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);