summaryrefslogtreecommitdiffstats
path: root/api.c
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2008-08-12 08:21:08 +0000
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2008-08-12 08:21:08 +0000
commit483688d70c2ca01a48ed92083d875b41ee4b145e (patch)
tree11e81c8d73e9b375586cb07399ae248b9614878b /api.c
parent9788476671e04b3d488a367169a3a51c03233c23 (diff)
downloadlibcg-483688d70c2ca01a48ed92083d875b41ee4b145e.tar.gz
libcg-483688d70c2ca01a48ed92083d875b41ee4b145e.tar.xz
libcg-483688d70c2ca01a48ed92083d875b41ee4b145e.zip
libcgroup: Extend cgroup_get_cgroup for uids as well.
Now that a new API is available which allows a cgroup structure to be generated with just a name, extend cgroup_get_cgroup to get the uids and gids from the fs itself. Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@127 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'api.c')
-rw-r--r--api.c58
1 files changed, 55 insertions, 3 deletions
diff --git a/api.c b/api.c
index a170e63..39703ac 100644
--- a/api.c
+++ b/api.c
@@ -703,11 +703,37 @@ static int cgroup_fill_cgc(struct dirent *ctrl_dir, struct cgroup *cgroup,
char *ctrl_file;
char *ctrl_value;
char *d_name;
+ char path[FILENAME_MAX+1];
char *buffer;
int error = 0;
+ struct stat stat_buffer;
d_name = strdup(ctrl_dir->d_name);
+ if (!strcmp(d_name, ".") || !strcmp(d_name, "..")) {
+ error = ECGINVAL;
+ goto fill_error;
+ }
+
+
+ /*
+ * This part really needs to be optimized out. Probably use
+ * some sort of a flag, but this is fine for now.
+ */
+
+ cg_build_path_locked(cgroup->name, path, cg_mount_table[index].name);
+ strcat(path, d_name);
+
+ error = stat(path, &stat_buffer);
+
+ if (!error) {
+ error = ECGFAIL;
+ goto fill_error;
+ }
+
+ cgroup->control_uid = stat_buffer.st_uid;
+ cgroup->control_gid = stat_buffer.st_gid;
+
ctrl_name = strtok_r(d_name, ".", &buffer);
if (!ctrl_name) {
@@ -718,13 +744,13 @@ static int cgroup_fill_cgc(struct dirent *ctrl_dir, struct cgroup *cgroup,
ctrl_file = strtok_r(NULL, ".", &buffer);
if (!ctrl_file) {
- error = ECGFAIL;
+ error = ECGINVAL;
goto fill_error;
}
if (strcmp(ctrl_name, cg_mount_table[index].name) == 0) {
ctrl_value = cg_rd_ctrl_file(cg_mount_table[index].name,
- cgroup->name, d_name);
+ cgroup->name, ctrl_dir->d_name);
if (!ctrl_value) {
error = ECGFAIL;
goto fill_error;
@@ -754,6 +780,8 @@ struct cgroup *cgroup_get_cgroup(struct cgroup *cgroup)
char path[FILENAME_MAX];
DIR *dir;
struct dirent *ctrl_dir;
+ char *control_path;
+ int error;
if (!cgroup_initialized) {
/* ECGROUPNOTINITIALIZED */
@@ -773,6 +801,8 @@ struct cgroup *cgroup_get_cgroup(struct cgroup *cgroup)
* cgroup_free_cgroup
*/
struct cgroup_controller *cgc;
+ struct stat stat_buffer;
+
if (!cg_build_path_locked(NULL, path,
cg_mount_table[i].name))
continue;
@@ -791,6 +821,27 @@ struct cgroup *cgroup_get_cgroup(struct cgroup *cgroup)
continue;
}
+ /*
+ * Get the uid and gid information
+ */
+
+ control_path = strdup(path);
+
+ if (!control_path)
+ goto unlock_error;
+
+ strcat(control_path, "tasks");
+
+ if (stat(control_path, &stat_buffer)) {
+ free(control_path);
+ goto unlock_error;
+ }
+
+ cgroup->tasks_uid = stat_buffer.st_uid;
+ cgroup->tasks_gid = stat_buffer.st_gid;
+
+ free(control_path);
+
cgc = cgroup_add_controller(cgroup,
cg_mount_table[i].name);
if (!cgc)
@@ -802,7 +853,8 @@ struct cgroup *cgroup_get_cgroup(struct cgroup *cgroup)
goto unlock_error;
}
while ((ctrl_dir = readdir(dir)) != NULL) {
- if (cgroup_fill_cgc(ctrl_dir, cgroup, cgc, i)) {
+ error = cgroup_fill_cgc(ctrl_dir, cgroup, cgc, i);
+ if (error == ECGFAIL) {
closedir(dir);
goto unlock_error;
}