[CRIU] [PATCH] criu: use strtok in parse_ns_string

Sophie Blee-Goldman ableegoldman at google.com
Tue Aug 5 21:28:24 PDT 2014


I wasn't aware that the -n option was no longer relevant, but in that case
this patch probably won't be needed. It was just there to prepare for the
user namespace support patches, which I will be sending out soon.

Thanks,

Sophie


On Tue, Aug 5, 2014 at 12:39 AM, Pavel Emelyanov <xemul at parallels.com>
wrote:

> On 08/05/2014 12:10 AM, Sophie Blee-Goldman wrote:
>
> Hi, Sophie
>
> > Use strtok to parse the -n option in crtools.c. Will be needed for
> implementing
> > user namespace support.
>
> Can you shed more light on this? The -n option only makes effect if
> used on restore from images generated by quite old version of criu.
> The prepare_pstree_kobj_ids()'s code
>
>                if (!item->ids) {
>                         if (item == root_item) {
>                                 cflags = opts.rst_namespaces_flags;
>                                 goto set_mask;
>                         }
>
> is about this -- item->ids is NULL only when images are created by
> criu older than 1.0.
>
> > Change-Id: Ifb7dc11c94c216a52cf9da7aab4fdf0af4f74152
>
> Remember putting the signed-off-by: line.
>
> > ---
> >  crtools.c | 40 ++++++++++++++++++++++------------------
> >  1 file changed, 22 insertions(+), 18 deletions(-)
> >
> > diff --git a/crtools.c b/crtools.c
> > index b7ca833..49b488a 100644
> > --- a/crtools.c
> > +++ b/crtools.c
> > @@ -53,30 +53,34 @@ void init_opts(void)
> >
> >  static int parse_ns_string(const char *ptr)
> >  {
> > -     const char *end = ptr + strlen(ptr);
> > +     int ret = 0;
> > +     char *ns;
> >
> > -     do {
> > -             if (ptr[3] != ',' && ptr[3] != '\0')
> > -                     goto bad_ns;
> > -             if (!strncmp(ptr, "uts", 3))
> > +     char *copy = strdup(ptr);
> > +     if (!copy) {
> > +             pr_msg("Error: malloc failed");
> > +             return -1;
> > +     }
> > +
> > +     for (ns = strtok(copy, ","); ns ; ns = strtok(NULL, ",")) {
> > +             if (!strcmp(ns, "uts")) {
> >                       opts.rst_namespaces_flags |= CLONE_NEWUTS;
> > -             else if (!strncmp(ptr, "ipc", 3))
> > +             } else if (!strcmp(ns, "ipc")) {
> >                       opts.rst_namespaces_flags |= CLONE_NEWIPC;
> > -             else if (!strncmp(ptr, "mnt", 3))
> > +             } else if (!strcmp(ns, "mnt")) {
> >                       opts.rst_namespaces_flags |= CLONE_NEWNS;
> > -             else if (!strncmp(ptr, "pid", 3))
> > +             } else if (!strcmp(ns, "pid")) {
> >                       opts.rst_namespaces_flags |= CLONE_NEWPID;
> > -             else if (!strncmp(ptr, "net", 3))
> > +             } else if (!strcmp(ns, "net")) {
> >                       opts.rst_namespaces_flags |= CLONE_NEWNET;
> > -             else
> > -                     goto bad_ns;
> > -             ptr += 4;
> > -     } while (ptr < end);
> > -     return 0;
> > -
> > -bad_ns:
> > -     pr_msg("Error: unknown namespace: %s\n", ptr);
> > -     return -1;
> > +             } else {
> > +                     pr_msg("Error: unknown namespace: %s\n", ns);
> > +                     ret = -1;
> > +                     break;
> > +             }
> > +     }
> > +     free(copy);
> > +     return ret;
> >  }
> >
> >  char criu_dir_name[PATH_MAX];
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvz.org/pipermail/criu/attachments/20140805/e21df6b5/attachment.html>


More information about the CRIU mailing list