This patch adds a new API to get the list of available controllers
in the cgroup data structure. To use, first call the API to get
the size of the list, and the next time pass in list to get the
names.

Signed-off-by: Dhaval Giani <[email protected]>
Cc: Jan Safranek <[email protected]>
---
 libcgroup.h   |    1 +
 libcgroup.map |    1 +
 wrapper.c     |   29 +++++++++++++++++++++++++++++
 3 files changed, 31 insertions(+)

Index: trunk/wrapper.c
===================================================================
--- trunk.orig/wrapper.c
+++ trunk/wrapper.c
@@ -600,3 +600,32 @@ out_error:
        }
        return ret;
 }
+
+int cgroup_list_controllers(struct cgroup *cgroup, char **list)
+{
+       int ret;
+       int i;
+
+       if (!cgroup)
+               return ECGINVAL;
+
+       if (!list)
+               return cgroup->index;
+
+       for (i = 0; i < cgroup->index; i++) {
+               list[i] = strdup(cgroup->controller[i]->name);
+               if (!list[i]) {
+                       ret = ECGOTHER;
+                       goto out_error;
+               }
+       }
+
+       return 0;
+
+out_error:
+       for (i = 0; i < cgroup->index && list[i]; i++) {
+               free(list[i]);
+               list[i] = NULL;
+       }
+       return ret;
+}
Index: trunk/libcgroup.h
===================================================================
--- trunk.orig/libcgroup.h
+++ trunk/libcgroup.h
@@ -247,6 +247,7 @@ int cgroup_set_value_bool(struct cgroup_
                                                const char *name, bool value);
 int cgroup_list_controller_files(struct cgroup *cgroup, char *name,
                                                        char **list);
+int cgroup_list_controllers(struct cgroup *cgroup, char **list);
 /*
  * Config related stuff
  */
Index: trunk/libcgroup.map
===================================================================
--- trunk.orig/libcgroup.map
+++ trunk/libcgroup.map
@@ -50,5 +50,6 @@ CGROUP_0.33 {
 global:
        cgroup_get_last_errno;
        cgroup_list_controller_files;
+       cgroup_list_controllers;
 } 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

Reply via email to