On Fri 20-05-11 14:50:28, Jan Safranek wrote:
> On 05/20/2011 02:36 PM, Michal Hocko wrote:
> > On Fri 20-05-11 14:25:09, Jan Safranek wrote:
> >> On 05/13/2011 02:01 PM, Michal Hocko wrote:
> >>> Let's add file permission for tasks and file and directory permissions
> >>> for control files into cgroup so that we can add them into configuration
> >>> files.
> >>> Permissions are initialized to -1U to reflect that no value is set.
> >>
> >> Mo magic numbers please... use #define or enum
> > 
> > In which header file should I put it?
> 
> probably in include/libcgroup/groups.h, where cg_chmod_recursive is
> defined, together with proper documentation.
> 
[...]
> >>>   config_cgroup_table = calloc(MAX_CGROUPS, sizeof(struct cgroup));
> >>> + if (!config_cgroup_table)
> >>> +         return ENOMEM;
> >>
> >> ECGFAIL, this is not kernel :)
> > 
> > OK, I have seen ENOMEM being used (e.g. cgroup_config_insert_cgroup).
> > Should I just return ECGFAIL and set last_error to ENOMEM?
> 
> Traditionally we return just ECGFAIL, without last_errno.

Updated patch:
---
>From 6cd0792957ee831cb1e2b21a691982ea157a78b3 Mon Sep 17 00:00:00 2001
From: Michal Hocko <mho...@suse.cz>
Date: Fri, 13 May 2011 14:01:29 +0200
Subject: [PATCH] Add file and directory permissions into cgroup

Let's add file permission for tasks and file and directory permissions
for control files into cgroup so that we can add them into configuration
files.
Permissions are initialized to NO_PERMS (unsigned -1 which doesn't
represent any valid permissions) to reflect that no value is set.  Let's
also add a common initialization functions for both cgroup table and
single cgroup.

Signed-off-by: Michal Hocko <mho...@suse.cz>
---
 include/libcgroup/groups.h |    4 ++++
 src/config.c               |    8 ++++++++
 src/libcgroup-internal.h   |    3 +++
 src/wrapper.c              |   15 ++++++++++++++-
 4 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/include/libcgroup/groups.h b/include/libcgroup/groups.h
index 1060641..61f18a0 100644
--- a/include/libcgroup/groups.h
+++ b/include/libcgroup/groups.h
@@ -109,6 +109,10 @@ struct cgroup;
  */
 struct cgroup_controller;
 
+/**
+ * Uninitialized file/directory permissions used for task/control files.
+ */
+#define NO_PERMS (-1U)
 
 /**
  * Allocate new cgroup structure. This function itself does not create new
diff --git a/src/config.c b/src/config.c
index 88b8356..3b9dceb 100644
--- a/src/config.c
+++ b/src/config.c
@@ -72,6 +72,8 @@ static int cgroup_table_index;
  */
 #define CGROUP_FILESYSTEM "cgroup"
 
+void init_cgroup_table(struct cgroup *cgroups, size_t count);
+
 /*
  * NOTE: All these functions return 1 on success
  * and not 0 as is the library convention
@@ -105,6 +107,7 @@ int cgroup_config_insert_cgroup(char *cg_name)
 
                memset(newblk + oldlen, 0, (MAX_CGROUPS - oldlen) *
                                sizeof(struct cgroup));
+               init_cgroup_table(newblk + oldlen, MAX_CGROUPS - oldlen);
                config_cgroup_table = newblk;
                cgroup_dbg("MAX_CGROUPS %d\n", MAX_CGROUPS);
                cgroup_dbg("reallocated config_cgroup_table to %p\n", 
config_cgroup_table);
@@ -687,6 +690,11 @@ int cgroup_config_load_config(const char *pathname)
        }
 
        config_cgroup_table = calloc(MAX_CGROUPS, sizeof(struct cgroup));
+       if (!config_cgroup_table)
+               return ECGFAIL;
+
+       init_cgroup_table(config_cgroup_table, MAX_CGROUPS);
+
        if (yyparse() != 0) {
                cgroup_dbg("Failed to parse file %s\n", pathname);
                fclose(yyin);
diff --git a/src/libcgroup-internal.h b/src/libcgroup-internal.h
index 801b35e..5cceada 100644
--- a/src/libcgroup-internal.h
+++ b/src/libcgroup-internal.h
@@ -84,8 +84,11 @@ struct cgroup {
        int index;
        uid_t tasks_uid;
        gid_t tasks_gid;
+       mode_t task_fperm;
        uid_t control_uid;
        gid_t control_gid;
+       mode_t control_fperm;
+       mode_t control_dperm;
 };
 
 
diff --git a/src/wrapper.c b/src/wrapper.c
index 4828ea8..90c8bc3 100644
--- a/src/wrapper.c
+++ b/src/wrapper.c
@@ -23,13 +23,26 @@
 #include <string.h>
 #include <unistd.h>
 
+static void init_cgroup(struct cgroup *cgroup)
+{
+       cgroup->task_fperm = cgroup->control_fperm = cgroup->control_dperm = 
NO_PERMS;
+}
+
+void init_cgroup_table(struct cgroup *cgroups, size_t count)
+{
+       size_t i;
+
+       for (i = 0; i < count; ++i)
+               init_cgroup(&cgroups[i]);
+}
+
 struct cgroup *cgroup_new_cgroup(const char *name)
 {
        struct cgroup *cgroup = calloc(1, sizeof(struct cgroup));
-
        if (!cgroup)
                return NULL;
 
+       init_cgroup(cgroup);
        strncpy(cgroup->name, name, sizeof(cgroup->name));
 
        return cgroup;
-- 
1.7.4.4


-- 
Michal Hocko
SUSE Labs
SUSE LINUX s.r.o.
Lihovarska 1060/12
190 00 Praha 9    
Czech Republic

------------------------------------------------------------------------------
What Every C/C++ and Fortran developer Should Know!
Read this article and learn how Intel has extended the reach of its 
next-generation tools to help Windows* and Linux* C/C++ and Fortran 
developers boost performance applications - including clusters. 
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to