summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBalbir Singh <balbir@linux.vnet.ibm.com>2009-04-24 09:52:14 +0530
committerBalbir Singh <balbir@linux.vnet.ibm.com>2009-04-24 09:52:14 +0530
commit739cdfd62e14d2558566cf73ce9e1702929cf834 (patch)
tree0e180c007728a8eedcbd6d806e902f1327de6b9c /src
parent01b53987d3587d026fcfc0f0486fed24e8737feb (diff)
parent7136dbf03169a9dbe515175c480276fb1877a7b1 (diff)
downloadlibcg-739cdfd62e14d2558566cf73ce9e1702929cf834.tar.gz
libcg-739cdfd62e14d2558566cf73ce9e1702929cf834.tar.xz
libcg-739cdfd62e14d2558566cf73ce9e1702929cf834.zip
Merge branch 'master' of ssh://balbir_singh@libcg.git.sourceforge.net/gitroot/libcg
Diffstat (limited to 'src')
-rw-r--r--src/api.c68
-rw-r--r--src/libcgroup.map10
2 files changed, 76 insertions, 2 deletions
diff --git a/src/api.c b/src/api.c
index 4d5b524..baeb856 100644
--- a/src/api.c
+++ b/src/api.c
@@ -2407,3 +2407,71 @@ int cgroup_read_stats_begin(char *controller, char *path, void **handle,
*handle = fp;
return ret;
}
+
+int cgroup_get_task_end(void **handle)
+{
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITIALIZED;
+
+ if (!*handle)
+ return ECGINVAL;
+
+ fclose((FILE *) *handle);
+ *handle = NULL;
+
+ return 0;
+}
+
+int cgroup_get_task_next(void *handle, pid_t *pid)
+{
+ int ret;
+
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITIALIZED;
+
+ if (!handle)
+ return ECGINVAL;
+
+ ret = fscanf((FILE *) handle, "%u", pid);
+
+ if (ret != 1) {
+ if (ret == EOF)
+ return ECGEOF;
+ last_errno = errno;
+ return ECGOTHER;
+ }
+
+ return 0;
+}
+
+int cgroup_get_task_begin(char *cgroup, char *controller, void **handle,
+ pid_t *pid)
+{
+ int ret = 0;
+ char path[FILENAME_MAX];
+ char *fullpath = NULL;
+
+ if (!cgroup_initialized)
+ return ECGROUPNOTINITIALIZED;
+
+ if (!cg_build_path(cgroup, path, controller))
+ return ECGOTHER;
+
+ ret = asprintf(&fullpath, "%s/tasks", path);
+
+ if (ret < 0) {
+ last_errno = errno;
+ return ECGOTHER;
+ }
+
+ *handle = (void *) fopen(fullpath, "r");
+ free(fullpath);
+
+ if (!*handle) {
+ last_errno = errno;
+ return ECGOTHER;
+ }
+ ret = cgroup_get_task_next(*handle, pid);
+
+ return ret;
+}
diff --git a/src/libcgroup.map b/src/libcgroup.map
index dd44fd7..4b95daa 100644
--- a/src/libcgroup.map
+++ b/src/libcgroup.map
@@ -52,8 +52,14 @@ global:
cgroup_walk_tree_begin;
cgroup_walk_tree_next;
cgroup_walk_tree_end;
+} CGROUP_0.32.1;
+
+CGROUP_0.34 {
+global:
+ cgroup_get_task_begin;
+ cgroup_get_task_end;
+ cgroup_get_task_next;
cgroup_read_stats_begin;
cgroup_read_stats_next;
cgroup_read_stats_end;
-} CGROUP_0.32.1;
-
+} CGROUP_0.33;