On 05/27/2011 02:56 PM, Jan Safranek wrote:
> The function changes permissions only in the first hierarchy, but it should
> change it in all of them.
> 
> Signed-off-by: Jan Safranek <jsafr...@redhat.com>
> ---
> 
>  src/api.c |   44 ++++++++++++++++++++++++++++----------------
>  1 files changed, 28 insertions(+), 16 deletions(-)
> 
> diff --git a/src/api.c b/src/api.c
> index 53c76e8..60e6df4 100644
> --- a/src/api.c
> +++ b/src/api.c
> @@ -211,30 +211,18 @@ int cg_chmod_file(FTS *fts, FTSENT *ent, mode_t 
> dir_mode,
>  /*
>   * TODO: Need to decide a better place to put this function.
>   */
> -int cg_chmod_recursive(struct cgroup *cgroup, mode_t dir_mode,
> +static int cg_chmod_recursive_controller(char *path, mode_t dir_mode,
>         int dirm_change, mode_t file_mode, int filem_change)
>  {
>       int ret = 0;
>       int final_ret =0;
>       FTS *fts;
>       char *fts_path[2];
> -     char *path = NULL;
>  
> -     fts_path[0] = (char *)malloc(FILENAME_MAX);
> -     if (!fts_path[0]) {
> -             last_errno = errno;
> -             return ECGOTHER;
> -     }
> +     fts_path[0] = path;
>       fts_path[1] = NULL;
> -     path = fts_path[0];
>       cgroup_dbg("chmod: path is %s\n", path);
>  
> -     if (!cg_build_path(cgroup->name, path,
> -                     cgroup->controller[0]->name)) {
> -             final_ret = ECGFAIL;
> -             goto err;
> -     }
> -
>       fts = fts_open(fts_path, FTS_PHYSICAL | FTS_NOCHDIR |
>                       FTS_NOSTAT, NULL);
>       if (fts == NULL) {

As Ivana pointed out privately, return code of fts_read later in this
function is not processed properly, I'll send new version shortly.

> @@ -257,12 +245,36 @@ int cg_chmod_recursive(struct cgroup *cgroup, mode_t 
> dir_mode,
>               }
>       }
>       fts_close(fts);
> -
>  err:
> -     free(fts_path[0]);
>       return final_ret;
>  }
>  
> +int cg_chmod_recursive(struct cgroup *cgroup, mode_t dir_mode,
> +             int dirm_change, mode_t file_mode, int filem_change)
> +{
> +     int i;
> +     char *path;
> +     int final_ret = 0;
> +     int ret;
> +
> +     path = malloc(FILENAME_MAX);
> +     if (!path)
> +             return ECGFAIL;
> +     for (i = 0; i < cgroup->index; i++) {
> +             if (!cg_build_path(cgroup->name, path,
> +                             cgroup->controller[i]->name)) {
> +                     final_ret = ECGFAIL;
> +                     goto err;
> +             }
> +             ret = cg_chmod_recursive_controller(path, dir_mode, dirm_change,
> +                             file_mode, filem_change);
> +             if (ret)
> +                     final_ret = ret;
> +     }
> +err:
> +     free(path);
> +     return final_ret;
> +}
>  
>  static char *cgroup_basename(const char *path)
>  {
> 
> 
> ------------------------------------------------------------------------------
> vRanger cuts backup time in half-while increasing security.
> With the market-leading solution for virtual backup and recovery, 
> you get blazing-fast, flexible, and affordable data protection.
> Download your free trial now. 
> http://p.sf.net/sfu/quest-d2dcopy1
> _______________________________________________
> Libcg-devel mailing list
> Libcg-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/libcg-devel


------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger. 
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today. 
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to