On 12/15/2012 07:00 PM, Ivana Hutarova Varekova wrote:
> Template cgroups mean control groups which are set in cgrules.conf file and 
> the name contains % variable like %U (see cgrules.conf manual page for the 
> whole list of variables).
> 
> This patch change cgroup_change_cgroup_flags function. Now if the wanted 
> group is template group and the group does not exist then 
> cgroup_change_cgroup_flags create the control group on the fly .
> 
> For now the created group can't be set - there is always used function 
> cgroup_create_cgroup. This will be changed in other patch in this patchset.
> 
> EXAMPLE:
> e.g.
>     @students   devices         people/students/%U
>     cgroup_change_cgroup_flags will create a cgroup /people/students/john if 
> user john from group students run a command and the people does not exist yet.
>     if /people/students group does not exist it will be created as well
> 
> CHANGELOG:
>       backslash -> slash
>       cgroup_copy_with_backslash: fix the index of final '/' character
>       add last_errno setting
>       fix comments
> 
> 
> Signed-off-by: Ivana Hutarova Varekova <varek...@redhat.com>
> ---
> 
>  src/api.c |  177 
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 177 insertions(+), 0 deletions(-)
> 
> diff --git a/src/api.c b/src/api.c
> index ea75cca..9cae6a0 100644
> --- a/src/api.c
> +++ b/src/api.c
> @@ -2635,6 +2635,176 @@ static struct cgroup_rule 
> *cgroup_find_matching_rule(uid_t uid,
>       return ret;
>  }
>  
> +/* Procedure the existence of cgroup "prefix" is in subsystem controller_name
> + * return 0 on success
> + */
> +int cgroup_exist_in_subsystem(char *controller_name, char *prefix)
> +{
> +     DIR *dir;
> +     char path[FILENAME_MAX];
> +
> +     pthread_rwlock_rdlock(&cg_mount_table_lock);
> +     if (!cg_build_path_locked(prefix, path, controller_name)) {
> +             pthread_rwlock_unlock(&cg_mount_table_lock);
> +             return 1;
> +     }
> +     pthread_rwlock_unlock(&cg_mount_table_lock);
> +
> +     dir = opendir(path);
> +     if (dir == NULL) {
> +             /* cgroup in wanted subsystem does not exist */
> +             return 1;
> +     } else {
> +             /* cgroup in wanted subsystem exists */
> +             return 0;
> +             closedir(dir);
> +     }
> +}
> +
> +/* auxiliary function return a pointer to the string
> + * which is copy of input string and end with the slash
> + */
> +char *cgroup_copy_with_slash(char *input)
> +{
> +     char *output;
> +     int len = strlen(input);
> +
> +     /* if input does not end with '/', allocate one more space for it */
> +     if ((input[len-2]) != '/')
> +             len = len+1;

Umm, what if len is less than 2? Then we have buffer underflow.

The rest of the patch is fine.

Acked-by: Jan Safranek<jsafr...@redhat.com>



------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to