[lxc-devel] [PATCH 1/1] lxc_id_mapping: don't try to write mappings if there are none
Stéphane Graber
stgraber at ubuntu.com
Wed Mar 13 15:42:31 UTC 2013
On 03/13/2013 11:33 AM, Serge Hallyn 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.vladimirov at gmail.com>
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
Looks good to me.
Acked-by: Stéphane Graber <stgraber at 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;
> }
>
>
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20130313/340c5eb9/attachment.pgp>
More information about the lxc-devel
mailing list