summaryrefslogtreecommitdiffstats
path: root/src/api.c
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/api.c
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/api.c')
-rw-r--r--src/api.c68
1 files changed, 68 insertions, 0 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;
+}