Commit 4f7521b4 by Serge Hallyn Committed by Stéphane Graber

lxc_id_mapping: don't try to write mappings if there are none

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: 's avatarAlexander Vladimirov <alexander.idkfa.vladimirov@gmail.com> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 6139e7e5
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment