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 > Let's also add a common initialization functions for both cgroup table > and single cgroup. > > Signed-off-by: Michal Hocko <mho...@suse.cz> > --- > src/config.c | 6 ++++++ > src/libcgroup-internal.h | 3 +++ > src/wrapper.c | 15 ++++++++++++++- > 3 files changed, 23 insertions(+), 1 deletions(-) > > diff --git a/src/config.c b/src/config.c > index f1873ea..7abec84 100644 > --- a/src/config.c > +++ b/src/config.c > @@ -105,6 +105,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); > @@ -712,6 +713,11 @@ int cgroup_config_load_config(const char *pathname) > } > > config_cgroup_table = calloc(MAX_CGROUPS, sizeof(struct cgroup)); > + if (!config_cgroup_table) > + return ENOMEM; ECGFAIL, this is not kernel :) On side note, we *should* have something like ECGNOMEM ... Adding to my todo list... > + > + 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 45c1ded..e79c038 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; > }; > > struct cg_mount_point { > diff --git a/src/wrapper.c b/src/wrapper.c > index 4828ea8..ce40394 100644 > --- a/src/wrapper.c > +++ b/src/wrapper.c > @@ -23,13 +23,26 @@ > #include <string.h> > #include <unistd.h> > > +void init_cgroup(struct cgroup *cgroup) > +{ > + cgroup->task_fperm = cgroup->control_fperm = cgroup->control_dperm = -1; > +} > + > +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; ------------------------------------------------------------------------------ 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