<p dir="ltr"><br>
On Nov 2, 2015 6:43 PM, "Serge Hallyn" <<a href="mailto:serge.hallyn@ubuntu.com">serge.hallyn@ubuntu.com</a>> wrote:<br>
><br>
> Quoting Christian Brauner (<a href="mailto:christianvanbrauner@gmail.com">christianvanbrauner@gmail.com</a>):<br>
> > On Mon, Nov 02, 2015 at 03:52:25PM +0100, Christian Brauner wrote:<br>
> > > On Mon, Nov 02, 2015 at 02:38:16PM +0000, Serge Hallyn wrote:<br>
> > > > Quoting Christian Brauner (<a href="mailto:christianvanbrauner@gmail.com">christianvanbrauner@gmail.com</a>):<br>
> > > > > This functions updates absolute paths for overlay upper- and workdirs so users<br>
> > > > > can simply clone and start new containers without worrying about absolute paths<br>
> > > > > in lxc.mount.entry overlay entries.<br>
> > > > ><br>
> > > > > Signed-off-by: Christian Brauner <<a href="mailto:christianvanbrauner@gmail.com">christianvanbrauner@gmail.com</a>><br>
> > > > > ---<br>
> > > > >  src/lxc/confile.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
> > > > >  src/lxc/confile.h |   3 ++<br>
> > > > >  2 files changed, 105 insertions(+)<br>
> > > > ><br>
> > > > > diff --git a/src/lxc/confile.c b/src/lxc/confile.c<br>
> > > > > index f7d6814..47b0b8b 100644<br>
> > > > > --- a/src/lxc/confile.c<br>
> > > > > +++ b/src/lxc/confile.c<br>
> > > > > @@ -2598,6 +2598,108 @@ void clear_unexp_config_line(struct lxc_conf *conf, const char *key, bool rm_sub<br>
> > > > >         }<br>
> > > > >  }<br>
> > > > ><br>
> > > > > +bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath,<br>
> > > > > +                                 const char *newpath, const char *oldname,<br>
> > > > > +                                 const char *newname, const char *ovldir)<br>
> > > > > +{<br>
> > > > > +       const char *key = "lxc.mount.entry";<br>
> > > > > +       int ret;<br>
> > > > > +       char *lstart = conf->unexpanded_config;<br>
> > > > > +       char *lend;<br>
> > > > > +       char *p;<br>
> > > > > +       char *q;<br>
> > > > > +       size_t newdirlen = strlen(ovldir) + strlen(newpath) + strlen(newname) + 2;<br>
> > > > > +       size_t olddirlen = strlen(ovldir) + strlen(oldpath) + strlen(oldname) + 2;<br>
> > > > > +       char *olddir = alloca(olddirlen + 1);<br>
> > > > > +       char *newdir = alloca(newdirlen + 1);<br>
> > > > > +<br>
> > > > > +       ret = snprintf(olddir, olddirlen + 1, "%s=%s/%s", ovldir, oldpath, oldname);<br>
> > > > > +       if (ret < 0 || ret >= olddirlen + 1) {<br>
> > > > > +               ERROR("Bug in %s", __func__);<br>
> > > > > +               return false;<br>
> > > > > +       }<br>
> > > > > +       ret = snprintf(newdir, newdirlen + 1, "%s=%s/%s", ovldir, newpath, newname);<br>
> > > > > +       if (ret < 0 || ret >= newdirlen + 1) {<br>
> > > > > +               ERROR("Bug in %s", __func__);<br>
> > > > > +               return false;<br>
> > > > > +       }<br>
> > > > > +       if (!conf->unexpanded_config)<br>
> > > > > +               return true;<br>
> > > > > +       while (*lstart) {<br>
> > > > > +               lend = strchr(lstart, '\n');<br>
> > > > > +               if (!lend)<br>
> > > > > +                       lend = lstart + strlen(lstart);<br>
> > > > > +               else<br>
> > > > > +                       lend++;<br>
> > > > > +               if (strncmp(lstart, key, strlen(key)) != 0) {<br>
> > > > > +                       lstart = lend;<br>
> > > > > +                       continue;<br>
> > > > > +               }<br>
> > > > > +               p = strchr(lstart + strlen(key), '=');<br>
> > > > > +               if (!p) {<br>
> > > > > +                       lstart = lend;<br>
> > > > > +                       continue;<br>
> > > > > +               }<br>
> > > > > +               p++;<br>
> > > > > +               while (isblank(*p))<br>
> > > > > +                       p++;<br>
> > > > > +               if (p >= lend)<br>
> > > > > +                        continue;<br>
> > > > > +                /* Whenever an lxc.mount.entry entry is found in a line we check<br>
> > > > > +                *  if the substring " overlay" or the substring " aufs" is<br>
> > > > > +                *  present before doing any further work. We check for "<br>
> > > > > +                *  overlay" and " aufs" since both substrings need to have at<br>
> > > > > +                *  least one space before them in a valid overlay<br>
> > > > > +                *  lxc.mount.entry (/A B overlay).  When the space before is<br>
> > > > > +                *  missing it is very likely that these substrings are part of a<br>
> > > > > +                *  path or something else. */<br>
> > > > > +               if (!strstr(p, " overlay") && !strstr(p, " aufs")) {<br>
> > > > > +                       lstart = lend;<br>
> > > > > +                       continue;<br>
> > > > > +               }<br>
> > > > > +               if (!(q = strstr(p, olddir))) {<br>
> > > > > +                       lstart = lend;<br>
> > > > > +                       continue;<br>
> > > > > +               }<br>
> > > ><br>
> > > > You're still not doing anything to ensure that 'overlays'/'aufs' and the<br>
> > > > olddir are actually occurring on this same line.  So they could be showing<br>
> > > > up in a comment or just later line.<br>
> ><br>
> > I don't think this is the case. At the beginning of the while() we search for a<br>
> > newline character and make lend point to the character immediately after it.<br>
> ><br>
> >               lend = strchr(lstart, '\n');<br>
> >               if (!lend)<br>
> >                       lend = lstart + strlen(lstart);<br>
> >               else<br>
> >                       lend++;<br>
> ><br>
> > Then we check<br>
> ><br>
> >               if (!strstr(p, " overlay") && !strstr(p, " aufs"))<br>
><br>
> strstr will not constrain it's search to values under lend (unless you<br>
> set *lend = '\0')<br>
><br>
> -serge</p>
<p dir="ltr">Searching for my mistake at the total wrong end... I'll fix it later tonight.<br>
</p>