This API allows the user to get a list of all the controller files for a certain controller. To use, first the API is called to get the total number of files, and in the next iteration is called to get the list of files.
Signed-off-by: Dhaval Giani <[email protected]> CC: Jan Safranek <[email protected]> --- libcgroup.h | 3 +++ libcgroup.map | 1 + wrapper.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) Index: trunk/wrapper.c =================================================================== --- trunk.orig/wrapper.c +++ trunk/wrapper.c @@ -555,3 +555,48 @@ int cgroup_set_value_bool(struct cgroup_ return cgroup_add_value_bool(controller, name, value); } + +/* + * Pass NULL for list, to get hte total number of elements + * Pass list (whihc has been allocated memory) to get the elements + * list should be an array of char* + */ +int cgroup_list_controller_files(struct cgroup *cgroup, char *name, char **list) +{ + struct cgroup_controller *cgc = NULL; + int i, j; + int ret; + + if (!cgroup || !name) + return ECGINVAL; + + for (i = 0; i < cgroup->index; i++) { + if (strcmp(cgroup->controller[i]->name, name) == 0) { + cgc = cgroup->controller[i]; + break; + } + } + + if (!cgc) + return ECGCONTROLLERNOTFOUND; + + if (!list) + return cgc->index; + + for (i = 0; i < cgc->index; i++) { + list[i] = strdup(cgc->values[i]->name); + if (!list[i]) { + ret = ECGOTHER; + goto out_error; + } + } + + return 0; + +out_error: + for (i = 0; i < cgc->index && list[i]; i++) { + free(list[i]); + list[i] = NULL; + } + return ret; +} Index: trunk/libcgroup.h =================================================================== --- trunk.orig/libcgroup.h +++ trunk/libcgroup.h @@ -99,6 +99,7 @@ enum cgroup_errors { ECGROUPPARSEFAIL, /* Failed to parse rules configuration file. */ ECGROUPNORULES, /* Rules list does not exist. */ ECGMOUNTFAIL, + ECGCONTROLLERNOTFOUND, ECGSENTINEL, /* Please insert further error codes above this */ }; @@ -244,6 +245,8 @@ int cgroup_get_value_bool(struct cgroup_ const char *name, bool *value); int cgroup_set_value_bool(struct cgroup_controller *controller, const char *name, bool value); +int cgroup_list_controller_files(struct cgroup *cgroup, char *name, + char **list); /* * Config related stuff */ Index: trunk/libcgroup.map =================================================================== --- trunk.orig/libcgroup.map +++ trunk/libcgroup.map @@ -49,5 +49,6 @@ global: CGROUP_0.33 { global: cgroup_get_last_errno; + cgroup_list_controller_files; } CGROUP_0.32.1; ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Libcg-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libcg-devel
