<div dir="ltr">> if (strlen(path) < PATH_MAX)<br><div><br></div><div>Shouldn't the comparison inmkdirpat() be >= instead of less than?</div><div><br></div><div>--Saied</div><div><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Mon, Jun 23, 2014 at 11:53 AM, Andrew Vagin <span dir="ltr"><<a href="mailto:avagin@parallels.com" target="_blank">avagin@parallels.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Mon, Jun 23, 2014 at 10:29:53PM +0400, Andrew Vagin wrote:<br>
> On Mon, Jun 23, 2014 at 03:54:22PM +0000, Tycho Andersen wrote:<br>
> > If a task had cgroups, these should be restored. (Also any properties of<br>
> > cgroups, but this commit doesn't do that yet.)<br>
> ><br>
> > Signed-off-by: Tycho Andersen <<a href="mailto:tycho.andersen@canonical.com">tycho.andersen@canonical.com</a>><br>
> > ---<br>
> > cgroup.c | 6 +++++-<br>
> > include/util.h | 5 +++++<br>
> > util.c | 26 ++++++++++++++++++++++++++<br>
> > 3 files changed, 36 insertions(+), 1 deletion(-)<br>
> ><br>
> > diff --git a/cgroup.c b/cgroup.c<br>
> > index 2d9ebad..8b2deb2 100644<br>
> > --- a/cgroup.c<br>
> > +++ b/cgroup.c<br>
> > @@ -258,9 +258,13 @@ static int move_in_cgroup(CgSetEntry *se)<br>
> > int fd, err;<br>
> > ControllerEntry *ce = se->ctls[i];<br>
> ><br>
> > + sprintf(aux, "%s/%s", ce->name, ce->path);<br>
> > + if (mkdirpat(cg, aux) < 0)<br>
> > + return -1;<br>
> > +<br>
> > sprintf(aux, "%s/%s/tasks", ce->name, ce->path);<br>
> > pr_debug(" `-> %s\n", aux);<br>
> > - err = fd = openat(cg, aux, O_WRONLY);<br>
> > + err = fd = openat(cg, aux, O_WRONLY | O_CREAT, 0700);<br>
> > if (fd >= 0) {<br>
> > /*<br>
> > * Writing zero into this file moves current<br>
> > diff --git a/include/util.h b/include/util.h<br>
> > index 22a0f3d..e2ec22e 100644<br>
> > --- a/include/util.h<br>
> > +++ b/include/util.h<br>
> > @@ -303,4 +303,9 @@ static inline bool strstartswith(char *str, char *sub)<br>
> > }<br>
> > }<br>
> ><br>
> > +/*<br>
> > + * mkdir -p for a file descriptor<br>
> > + */<br>
> > +int mkdirpat(int fd, const char* path);<br>
> > +<br>
> > #endif /* __CR_UTIL_H__ */<br>
> > diff --git a/util.c b/util.c<br>
> > index 975af30..7d235c6 100644<br>
> > --- a/util.c<br>
> > +++ b/util.c<br>
> > @@ -677,3 +677,29 @@ struct vma_area *alloc_vma_area(void)<br>
> ><br>
> > return p;<br>
> > }<br>
> > +<br>
> > +int mkdirpat(int fd, const char* path)<br>
> > +{<br>
> > + char* tok;<br>
> > + char made_path[PATH_MAX] = "", tok_path[PATH_MAX];<br>
> > +<br>
> > + if (strlen(path) < PATH_MAX)<br>
> > + {<br>
> > + pr_err("path %s is longer than PATH_MAX", path);<br>
> > + return -1;<br>
> > + }<br>
> > +<br>
> > + strncpy(tok_path, path, PATH_MAX);<br>
> > +<br>
> > + for(tok = strtok(tok_path, "/"); tok; tok = strtok(NULL, "/")) {<br>
><br>
> tok = strtok(NULL, "/") always returns NULL<br>
<br>
</div></div>Sorry, pls ignore this comment.<br>
<div class=""><br>
><br>
> > + strcat(made_path, tok);<br>
> > + strcat(made_path, "/");<br>
> > + if (mkdirat(fd, made_path, 0755) < 0 && errno != EEXIST) {<br>
> > + pr_perror("couldn't mkdirpat directory\n");<br>
> > + return -1;<br>
> > + }<br>
> > + }<br>
<br>
</div>Look at my version. It doesn't copy a path in another place.<br>
<br>
tok = path;<br>
while (tok = strchr(tok + 1, "/")) {<br>
char c;<br>
if (tok != NULL) {<br>
c = *tok;<br>
*tok = 0;<br>
}<br>
<br>
if (mkdirat(fd, path, 0755) < 0 && errno != EEXIST) {<br>
<div class=""> pr_perror("couldn't mkdirpat directory\n");<br>
</div> return -1;<br>
}<br>
<br>
if (tok == NULL)<br>
break;<br>
else<br>
*tok = c;<br>
}<br>
<br>
Thanks.<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
CRIU mailing list<br>
<a href="mailto:CRIU@openvz.org">CRIU@openvz.org</a><br>
<a href="https://lists.openvz.org/mailman/listinfo/criu" target="_blank">https://lists.openvz.org/mailman/listinfo/criu</a><br>
</div></div></blockquote></div><br></div>