[CRIU] [PATCH 5/5] userns: restore gid and uid maps
Andrew Vagin
avagin at parallels.com
Tue Feb 11 05:13:46 PST 2014
On Tue, Feb 11, 2014 at 08:50:35AM +0400, Pavel Emelyanov wrote:
> > +static int write_id_map(pid_t pid, UidGidExtent **extents, int n, char *id_map)
> > +{
> > + char buf[PAGE_SIZE];
> > + int off = 0, i;
> > + int fd;
> > +
> > + for (i = 0; i < n; i++)
> > + off += snprintf(buf + off, sizeof(buf) - off,
> > + "%d %d %d", extents[i]->first,
> > + extents[i]->lower_first,
> > + extents[i]->count);
>
> Maybe use fopen_proc for that? This would avoid allocating
> one more buffer on the stack.
* We don't have fopen_proc_rw
* {u,g}id_map files can be written only once
so we can't use stream here.
>
> > +
> > + fd = open_proc_rw(pid, "%s", id_map);
> > + if (fd < 0)
> > + return -1;
> > + if (write(fd, buf, off) != off) {
> > + pr_perror("Unable to write into %s\n", id_map);
> > + close(fd);
> > + return -1;
> > + }
> > + close(fd);
> > +
> > + return 0;
> > +}
> > +
> > +int prepare_userns(struct pstree_item *item)
> > +{
> > + UsernsEntry *e;
> > + int fd, ret;
> > +
> > + fd = open_image(CR_FD_USERNS, O_RSTR, item->ids->user_ns_id);
> > + ret = pb_read_one(fd, &e, PB_USERNS);
> > + close(fd);
> > + if (ret < 0)
> > + return -1;
> > +
> > + if (write_id_map(item->pid.real, e->uid_map, e->n_uid_map, "uid_map"))
> > + return -1;
> > +
> > + if (write_id_map(item->pid.real, e->gid_map, e->n_gid_map, "gid_map"))
> > + return -1;
> > +
> > + return 0;
> > +}
> > +
> > int prepare_namespace(struct pstree_item *item, unsigned long clone_flags)
> > {
> > pid_t pid = item->pid.virt;
> >
>
>
More information about the CRIU
mailing list