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