<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="auto"><div><div class="gmail_quote"><div dir="ltr">чт, 7 февр. 2019 г., 15:12 Cyrill Gorcunov <a href="mailto:gorcunov@gmail.com" target="_blank">gorcunov@gmail.com</a>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">To make sure we reorder ghost directories properly.<br>
<br>
Signed-off-by: Cyrill Gorcunov &lt;<a href="mailto:gorcunov@gmail.com" rel="noreferrer" target="_blank">gorcunov@gmail.com</a>&gt;<br>
---<br>
 test/zdtm/static/Makefile     |   1 +<br>
 test/zdtm/static/unlink_dir.c | 106 ++++++++++++++++++++++++++++++++++<br>
 2 files changed, 107 insertions(+)<br>
 create mode 100644 test/zdtm/static/unlink_dir.c<br>
<br>
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile<br>
index ddbc0fdd67c8..4700ac783baa 100644<br>
--- a/test/zdtm/static/Makefile<br>
+++ b/test/zdtm/static/Makefile<br>
@@ -343,6 +343,7 @@ TST_DIR             =                               \<br>
                shared_slave_mount_children     \<br>
                non_uniform_share_propagation   \<br>
                private_bind_propagation        \<br>
+               unlink_dir                      \<br>
<br>
 TST_DIR_FILE   =                               \<br>
                chroot                          \<br>
diff --git a/test/zdtm/static/unlink_dir.c b/test/zdtm/static/unlink_dir.c<br>
new file mode 100644<br>
index 000000000000..1d9a19bc481c<br>
--- /dev/null<br>
+++ b/test/zdtm/static/unlink_dir.c<br>
@@ -0,0 +1,106 @@<br>
+#include &lt;stdlib.h&gt;<br>
+#include &lt;fcntl.h&gt;<br>
+#include &lt;errno.h&gt;<br>
+#include &lt;unistd.h&gt;<br>
+#include &lt;string.h&gt;<br>
+<br>
+#include &lt;sys/types.h&gt;<br>
+#include &lt;sys/stat.h&gt;<br>
+<br>
+#include &lt;linux/limits.h&gt;<br>
+<br>
+#include &quot;zdtmtst.h&quot;<br>
+<br>
+const char *test_doc   = &quot;Check cleanup order of ghost directory and files inside&quot;;<br>
+const char *test_author        = &quot;Cyrill Gorcunov &lt;<a href="mailto:gorcunov@openvz.org" rel="noreferrer" target="_blank">gorcunov@openvz.org</a>&gt;&quot;;<br>
+<br>
+char *dirname;<br>
+TEST_OPTION(dirname, string, &quot;directory name&quot;, 1);<br>
+<br>
+int main(int argc, char ** argv)<br>
+{<br>
+       int fds[4], dirfd1, dirfd2, i, len;<br>
+       char path_dir1[PATH_MAX];<br>
+       char path_dir2[PATH_MAX];<br>
+       char path[PATH_MAX];<br>
+<br>
+       int lo = ARRAY_SIZE(fds) / 2;<br>
+       int hi = ARRAY_SIZE(fds);<br>
+<br>
+       test_init(argc, argv);<br>
+<br>
+       if (mkdir(dirname, 0700) &lt; 0) {<br>
+               pr_perror(&quot;Can&#39;t create directory %s&quot;, dirname);<br>
+               return 1;<br>
+       }<br>
+<br>
+       len = snprintf(path_dir1, sizeof(path_dir1), &quot;%s/%s&quot;, dirname, &quot;gd1&quot;);<br>
+       if (len == sizeof(path_dir1)) path_dir1[len-1] = &#39;\0&#39;;<br></blockquote><div><br></div><div>Expression above is strange as snprintf always prints terminating null byte, even if it needs to truncate the output. In other code we either ignore the return of snprintf assuming that we can&#39;t have truncation or do check error like: if (len &gt;= sizeof(path_dir1)) return -1;<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+       if (mkdir(path_dir1, 0700) &lt; 0) {<br>
+               pr_perror(&quot;Can&#39;t create directory %s&quot;, path_dir1);<br>
+               return 1;<br>
+       }<br>
+<br>
+       len = snprintf(path_dir2, sizeof(path_dir2), &quot;%s/%s/%s&quot;, dirname, &quot;gd1&quot;, &quot;gd2&quot;);<br>
+       if (len == sizeof(path_dir2)) path_dir2[len-1] = &#39;\0&#39;;<br></blockquote><div>/tmp/snprintf.c<br></div><div>same here<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+       if (mkdir(path_dir2, 0700) &lt; 0) {<br>
+               pr_perror(&quot;Can&#39;t create directory %s&quot;, path_dir2);<br>
+               return 1;<br>
+       }<br>
+<br>
+       for (i = 0; i &lt; lo; i++) {<br>
+               len = snprintf(path, sizeof(path), &quot;%s/%d&quot;, path_dir1, i);<br>
+               if (len == sizeof(path)) path[len-1] = &#39;\0&#39;;<br></blockquote><div><br></div><div>same here<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+               fds[i] = open(path, O_RDONLY | O_CREAT | O_TRUNC);<br>
+               if (fds[i] &lt; 0) {<br>
+                       pr_perror(&quot;Can&#39;t open %s&quot;, path);<br>
+                       return 1;<br>
+               }<br>
+               if (unlink(path)) {<br>
+                       pr_perror(&quot;Can&#39;t unlink %s&quot;, path);<br>
+                       return 1;<br>
+               }<br>
+       }<br>
+<br>
+       dirfd2 = open(path_dir2, O_RDONLY | O_DIRECTORY);<br>
+       if (dirfd2 &lt; 0) {<br>
+               pr_perror(&quot;Can&#39;t open %s&quot;, path_dir2);<br>
+               return 1;<br>
+       }<br>
+<br>
+       for (i = lo; i &lt; hi; i++) {<br>
+               len = snprintf(path, sizeof(path), &quot;%s/%d&quot;, path_dir2, i);<br>
+               if (len == sizeof(path)) path[len-1] = &#39;\0&#39;;<br></blockquote><div><br></div><div>same here<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+               fds[i] = open(path, O_RDONLY | O_CREAT | O_TRUNC);<br>
+               if (fds[i] &lt; 0) {<br>
+                       pr_perror(&quot;Can&#39;t open %s&quot;, path);<br>
+                       return 1;<br>
+               }<br>
+               if (unlink(path)) {<br>
+                       pr_perror(&quot;Can&#39;t unlink %s&quot;, path);<br>
+                       return 1;<br>
+               }<br>
+       }<br>
+<br>
+       dirfd1 = open(path_dir1, O_RDONLY | O_DIRECTORY);<br>
+       if (dirfd1 &lt; 0) {<br>
+               pr_perror(&quot;Can&#39;t open %s&quot;, path_dir1);<br>
+               return 1;<br>
+       }<br>
+<br>
+       if (rmdir(path_dir2)) {<br>
+               pr_perror(&quot;Can&#39;t rmdir %s&quot;, path_dir2);<br>
+               return 1;<br>
+       }<br>
+<br>
+       if (rmdir(path_dir1)) {<br>
+               pr_perror(&quot;Can&#39;t rmdir %s&quot;, path_dir1);<br>
+               return 1;<br>
+       }<br>
+<br>
+       test_daemon();<br>
+       test_waitsig();<br>
+<br>
+       pass();<br>
+       return 0;<br>
+}<br>
-- <br>
2.20.1<br>
<br>
_______________________________________________<br>
CRIU mailing list<br>
<a href="mailto:CRIU@openvz.org" rel="noreferrer" target="_blank">CRIU@openvz.org</a><br>
<a href="https://lists.openvz.org/mailman/listinfo/criu" rel="noreferrer noreferrer" target="_blank">https://lists.openvz.org/mailman/listinfo/criu</a><br>
</blockquote></div></div></div>
</div></div></div></div>