diff options
author | Balbir Singh <balbir@linux.vnet.ibm.com> | 2009-04-24 09:52:14 +0530 |
---|---|---|
committer | Balbir Singh <balbir@linux.vnet.ibm.com> | 2009-04-24 09:52:14 +0530 |
commit | 739cdfd62e14d2558566cf73ce9e1702929cf834 (patch) | |
tree | 0e180c007728a8eedcbd6d806e902f1327de6b9c /src | |
parent | 01b53987d3587d026fcfc0f0486fed24e8737feb (diff) | |
parent | 7136dbf03169a9dbe515175c480276fb1877a7b1 (diff) | |
download | libcg-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.c | 68 | ||||
-rw-r--r-- | src/libcgroup.map | 10 |
2 files changed, 76 insertions, 2 deletions
@@ -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; |