diff options
author | Ivana Hutarova Varekova <varekova@redhat.com> | 2009-07-17 09:41:12 +0200 |
---|---|---|
committer | Dhaval Giani <dhaval@linux.vnet.ibm.com> | 2009-08-06 11:59:15 +0530 |
commit | 0d943b1fd84f43edda88d8f1e45a2cfe56b0edeb (patch) | |
tree | f9b6b23aaede896427be5b295a57109f53a891a9 /src/api.c | |
parent | 5aa993cef39ffd59eae1e363c2a731a03507b0d3 (diff) | |
download | libcg-0d943b1fd84f43edda88d8f1e45a2cfe56b0edeb.tar.gz libcg-0d943b1fd84f43edda88d8f1e45a2cfe56b0edeb.tar.xz libcg-0d943b1fd84f43edda88d8f1e45a2cfe56b0edeb.zip |
add api for generating the list of all controllers (not only mount ones)
this patch add api for generating the list of all controllers (not only mount ones)
- it uses three functions:
cgroup_get_all_controller_begin
cgroup_get_all_controller_next
cgroup_get_all_controller_end
and structure:
struct controller_data {
char name[FILENAME_MAX];
int hierarchy;
int num_cgroups;
int enabled;
};
the data are read from /proc/cgroups file
Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com>
Reviewed-by: Jan Safranek <jsafrane@redhat.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
Diffstat (limited to 'src/api.c')
-rw-r--r-- | src/api.c | 76 |
1 files changed, 76 insertions, 0 deletions
@@ -3232,3 +3232,79 @@ out_exit: pthread_rwlock_unlock(&cg_mount_table_lock); return ret; } + + +int cgroup_get_all_controller_end(void **handle) +{ + FILE *proc_cgroup = (FILE *) *handle; + + if (!cgroup_initialized) + return ECGROUPNOTINITIALIZED; + + if (!proc_cgroup) + return ECGINVAL; + + fclose(proc_cgroup); + *handle = NULL; + + return 0; +} + + +int cgroup_get_all_controller_next(void **handle, struct controller_data *info) +{ + FILE *proc_cgroup = (FILE *) *handle; + int err = 0; + int hierarchy, num_cgroups, enabled; + char subsys_name[FILENAME_MAX]; + + if (!cgroup_initialized) + return ECGROUPNOTINITIALIZED; + + if (!proc_cgroup) + return ECGINVAL; + + if (!info) + return ECGINVAL; + + err = fscanf(proc_cgroup, "%s %d %d %d\n", subsys_name, + &hierarchy, &num_cgroups, &enabled); + + if (err != 4) + return ECGEOF; + + strncpy(info->name, subsys_name, FILENAME_MAX); + info->name[FILENAME_MAX-1] = '\0'; + info->hierarchy = hierarchy; + info->num_cgroups = num_cgroups; + info->enabled = enabled; + + return 0; +} + + +int cgroup_get_all_controller_begin(void **handle, struct controller_data *info) +{ + FILE *proc_cgroup = NULL; + char buf[FILENAME_MAX]; + + if (!cgroup_initialized) + return ECGROUPNOTINITIALIZED; + + if (!info) + return ECGINVAL; + + proc_cgroup = fopen("/proc/cgroups", "r"); + if (!proc_cgroup) { + last_errno = errno; + return ECGOTHER; + } + + if (!fgets(buf, FILENAME_MAX, proc_cgroup)) { + last_errno = errno; + return ECGOTHER; + } + *handle = proc_cgroup; + + return cgroup_get_all_controller_next(handle, info); +} |