<div dir="ltr"><div>From: Yicheng Qin <<a href="mailto:yichengq@google.com">yichengq@google.com</a>></div><div>Subject: [PATCH] test/zdtm/sockets_dgram: Use shorter pathname to support</div><div> struct sockaddr_un</div>
<div><br></div><div>Struct sockaddr_un is used in program for bind() to listen on a local file.</div><div><br></div><div>Path is one of its attributes and only has 108-byte size. It may happen</div><div>that the path is too small to contain the whole real path, which contains</div>
<div>current working directory now. This may lead to two sockets listening on</div><div>the same file.</div><div><br></div><div>So, we change the path to be "/tmp". It ensures that filename cannot</div><div>exceed the limit.</div>
<div><br></div><div>Additionally, to run it well with namespace, make new directory named</div><div>'tmp' under constructed root.</div><div><br></div><div>Signed-off-by: Yicheng Qin <<a href="mailto:yichengq@google.com">yichengq@google.com</a>></div>
<div>---</div><div> test/zdtm.sh | 5 +++++</div><div> test/zdtm/live/static/sockets_dgram.c | 32 +++++++++++++++++++++-----------</div><div> 2 files changed, 26 insertions(+), 11 deletions(-)</div>
<div><br></div><div>diff --git a/test/zdtm.sh b/test/zdtm.sh</div><div>index 98eb075..f640cd7 100755</div><div>--- a/test/zdtm.sh</div><div>+++ b/test/zdtm.sh</div><div>@@ -223,6 +223,7 @@ construct_root()</div><div> <span class="" style="white-space:pre">        </span>local ps_path=`type -P ps`</div>
<div> <span class="" style="white-space:pre">        </span>local libdir=$root/lib</div><div> <span class="" style="white-space:pre">        </span>local libdir2=$root/lib64</div><div>+<span class="" style="white-space:pre">        </span>local tmpdir=$root/tmp</div>
<div> </div><div> <span class="" style="white-space:pre">        </span>mkdir -p $root/bin</div><div> <span class="" style="white-space:pre">        </span>cp $ps_path $root/bin</div><div>@@ -250,6 +251,10 @@ construct_root()</div><div>
<span class="" style="white-space:pre">                </span>[ -f /lib/x86_64-linux-gnu/$i ] && cp /lib/x86_64-linux-gnu/$i $libdir && cp /lib/x86_64-linux-gnu/$i $libdir2 && continue ||</div><div> <span class="" style="white-space:pre">                </span>[ -f /lib/arm-linux-gnueabi/$i ] && cp /lib/arm-linux-gnueabi/$i $libdir && cp /lib/arm-linux-gnueabi/$i $libdir2 && continue || echo "Failed at " $i && return 1</div>
<div> <span class="" style="white-space:pre">        </span>done</div><div>+</div><div>+<span class="" style="white-space:pre">        </span># make 'tmp' dir under new root</div><div>+<span class="" style="white-space:pre">        </span>mkdir $tmpdir</div>
<div>+<span class="" style="white-space:pre">        </span>chmod 0777 $tmpdir</div><div> }</div><div> </div><div> export MAKEFLAGS=--no-print-directory</div><div>diff --git a/test/zdtm/live/static/sockets_dgram.c b/test/zdtm/live/static/sockets_dgram.c</div>
<div>index 1df0570..6bdb857 100644</div><div>--- a/test/zdtm/live/static/sockets_dgram.c</div><div>+++ b/test/zdtm/live/static/sockets_dgram.c</div><div>@@ -39,19 +39,22 @@ int main(int argc, char *argv[])</div><div> </div>
<div> <span class="" style="white-space:pre">        </span>char path[PATH_MAX];</div><div> <span class="" style="white-space:pre">        </span>char buf[64];</div><div>-<span class="" style="white-space:pre">        </span>char *cwd;</div><div>
+<span class="" style="white-space:pre">        </span>/*</div><div>+<span class="" style="white-space:pre">        </span> * The original code makes dir to be current working</div><div>+<span class="" style="white-space:pre">        </span> * directory. But it may be too long in google environment</div>
<div>+<span class="" style="white-space:pre">        </span> * for path to be fit into struct sockaddr_un.</div><div>+<span class="" style="white-space:pre">        </span> * One alternate way to resolve it is to use relative path</div>
<div>+<span class="" style="white-space:pre">        </span> * for sockaddr_un, but criu has not supported relative</div><div>+<span class="" style="white-space:pre">        </span> * bind path yet.</div><div>+<span class="" style="white-space:pre">        </span> * We change it to "/tmp" to ensure its short length.</div>
<div>+<span class="" style="white-space:pre">        </span> */</div><div>+<span class="" style="white-space:pre">        </span>char *dirname = "/tmp";</div><div> </div><div> <span class="" style="white-space:pre">        </span>int ret;</div>
<div> </div><div> <span class="" style="white-space:pre">        </span>test_init(argc, argv);</div><div> </div><div>-<span class="" style="white-space:pre">        </span>cwd = get_current_dir_name();</div><div>-<span class="" style="white-space:pre">        </span>if (!cwd) {</div>
<div>-<span class="" style="white-space:pre">                </span>fail("getcwd\n");</div><div>-<span class="" style="white-space:pre">                </span>exit(1);</div><div>-<span class="" style="white-space:pre">        </span>}</div><div>-</div>
<div>-<span class="" style="white-space:pre">        </span>snprintf(path, sizeof(path), "%s/%s", cwd, filename);</div><div>+<span class="" style="white-space:pre">        </span>snprintf(path, sizeof(path), "%s/%s", dirname, filename);</div>
<div> <span class="" style="white-space:pre">        </span>unlink(path);</div><div> </div><div> <span class="" style="white-space:pre">        </span>sk_dgram_bound_client<span class="" style="white-space:pre">        </span>= socket(AF_UNIX, SOCK_DGRAM, 0);</div>
<div>@@ -71,7 +74,7 @@ int main(int argc, char *argv[])</div><div> <span class="" style="white-space:pre">                </span>exit(1);</div><div> <span class="" style="white-space:pre">        </span>}</div><div> </div><div>-<span class="" style="white-space:pre">        </span>snprintf(path, sizeof(path), "%s/%s.bound", cwd, filename);</div>
<div>+<span class="" style="white-space:pre">        </span>snprintf(path, sizeof(path), "%s/%s.bound", dirname, filename);</div><div> <span class="" style="white-space:pre">        </span>unlink(path);</div><div> <span class="" style="white-space:pre">        </span>if (strlen(path) >= sizeof(name_bound.sun_path)) {</div>
<div> <span class="" style="white-space:pre">                </span>fail("too long path");</div><div>@@ -81,7 +84,7 @@ int main(int argc, char *argv[])</div><div> <span class="" style="white-space:pre">        </span>name_bound.sun_family = AF_UNIX;</div>
<div> <span class="" style="white-space:pre">        </span>strncpy(name_bound.sun_path, path, sizeof(name_bound.sun_path));</div><div> </div><div>-<span class="" style="white-space:pre">        </span>snprintf(path, sizeof(path), "%s/%s.conn", cwd, filename);</div>
<div>+<span class="" style="white-space:pre">        </span>snprintf(path, sizeof(path), "%s/%s.conn", dirname, filename);</div><div> <span class="" style="white-space:pre">        </span>unlink(path);</div><div> <span class="" style="white-space:pre">        </span>if (strlen(path) >= sizeof(name_conn.sun_path)) {</div>
<div> <span class="" style="white-space:pre">                </span>fail("too long path");</div><div>@@ -91,7 +94,7 @@ int main(int argc, char *argv[])</div><div> <span class="" style="white-space:pre">        </span>name_conn.sun_family = AF_UNIX;</div>
<div> <span class="" style="white-space:pre">        </span>strncpy(name_conn.sun_path, path, sizeof(name_conn.sun_path));</div><div> </div><div>-<span class="" style="white-space:pre">        </span>snprintf(path, sizeof(path), "%s/%s.bound-conn", cwd, filename);</div>
<div>+<span class="" style="white-space:pre">        </span>snprintf(path, sizeof(path), "%s/%s.bound-conn", dirname, filename);</div><div> <span class="" style="white-space:pre">        </span>unlink(path);</div><div> <span class="" style="white-space:pre">        </span>if (strlen(path) >= sizeof(name_bound_conn.sun_path)) {</div>
<div> <span class="" style="white-space:pre">                </span>fail("too long path");</div><div>@@ -198,5 +201,12 @@ int main(int argc, char *argv[])</div><div> <span class="" style="white-space:pre">        </span>test_msg("dgram-bound-conn : '%s'\n", buf);</div>
<div> </div><div> <span class="" style="white-space:pre">        </span>pass();</div><div>+</div><div>+<span class="" style="white-space:pre">        </span>/*</div><div>+<span class="" style="white-space:pre">        </span> * Do cleanup work</div>
<div>+<span class="" style="white-space:pre">        </span> */</div><div>+<span class="" style="white-space:pre">        </span>unlink(name_bound.sun_path);</div><div>+<span class="" style="white-space:pre">        </span>unlink(name_conn.sun_path);</div>
<div>+<span class="" style="white-space:pre">        </span>unlink(name_bound_conn.sun_path);</div><div> <span class="" style="white-space:pre">        </span>return 0;</div><div> }</div><div>-- </div><div>1.8.3</div><div><br></div></div>