Thanks for fixing this up Serge, sorry about the regression!

On Wed, 13 Mar 2013 10:33:00 -0500
Serge Hallyn <serge.hal...@ubuntu.com> wrote:

> Otherwise containers fail to start even if they aren't trying to map
> ids.
> 
> Also don't allocate buf unless we need to.
> 
> Reported-by: Alexander Vladimirov
> <alexander.idkfa.vladimi...@gmail.com> Signed-off-by: Serge Hallyn
> <serge.hal...@ubuntu.com> ---
>  src/lxc/conf.c | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> index 85e1c61..af75690 100644
> --- a/src/lxc/conf.c
> +++ b/src/lxc/conf.c
> @@ -2479,17 +2479,20 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t
> pid) struct lxc_list *iterator;
>       struct id_map *map;
>       int ret = 0;
> -     char *buf,*pos;
>       enum idtype type;
> -
> -     /* The kernel only takes <= 4k for writes
> to /proc/<nr>/[ug]id_map */
> -     buf = pos = malloc(4096);
> -     if (!buf)
> -             return -ENOMEM;
> +     char *buf = NULL, *pos;
>  
>       for(type = ID_TYPE_UID; type <= ID_TYPE_GID; type++) {
> -             int left,fill;
> +             int left, fill;
> +
> +             pos = buf;
>               lxc_list_for_each(iterator, idmap) {
> +                     /* The kernel only takes <= 4k for writes
> to /proc/<nr>/[ug]id_map */
> +                     if (!buf)
> +                             buf = pos = malloc(4096);
> +                     if (!buf)
> +                             return -ENOMEM;
> +
>                       map = iterator->elem;
>                       if (map->idtype == type) {
>                               left = 4096 - (pos - buf);
> @@ -2500,13 +2503,15 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t
> pid) pos += fill;
>                       }
>               }
> +             if (pos == buf) // no mappings were found
> +                     continue;
>               ret = write_id_mapping(type, pid, buf, pos-buf);
>               if (ret)
>                       break;
> -             pos = buf;
>       }
>  
> -     free(buf);
> +     if (buf)
> +             free(buf);
>       return ret;
>  }
>  


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to