Commit 73a6dcbc authored by Yicheng Qin's avatar Yicheng Qin Committed by Pavel Emelyanov

test/zdtm/sockets_dgram: Use shorter pathname to support

 struct sockaddr_un

Struct sockaddr_un is used in program for bind() to listen on a local file.

Path is one of its attributes and only has 108-byte size. It may happen
that the path is too small to contain the whole real path, which contains
current working directory now. This may lead to two sockets listening on
the same file.

So, we change the path to be "/tmp". It ensures that filename cannot
exceed the limit.

Additionally, to run it well with namespace, make new directory named
'tmp' under constructed root.
Signed-off-by: 's avatarYicheng Qin <yichengq@google.com>
Acked-by: 's avatarAndrew Vagin <avagin@parallels.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent de0c3b95
...@@ -223,6 +223,7 @@ construct_root() ...@@ -223,6 +223,7 @@ construct_root()
local ps_path=`type -P ps` local ps_path=`type -P ps`
local libdir=$root/lib local libdir=$root/lib
local libdir2=$root/lib64 local libdir2=$root/lib64
local tmpdir=$root/tmp
mkdir -p $root/bin mkdir -p $root/bin
cp $ps_path $root/bin cp $ps_path $root/bin
...@@ -250,6 +251,10 @@ construct_root() ...@@ -250,6 +251,10 @@ construct_root()
[ -f /lib/x86_64-linux-gnu/$i ] && cp /lib/x86_64-linux-gnu/$i $libdir && cp /lib/x86_64-linux-gnu/$i $libdir2 && continue || [ -f /lib/x86_64-linux-gnu/$i ] && cp /lib/x86_64-linux-gnu/$i $libdir && cp /lib/x86_64-linux-gnu/$i $libdir2 && continue ||
[ -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 [ -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
done done
# make 'tmp' dir under new root
mkdir $tmpdir
chmod 0777 $tmpdir
} }
export MAKEFLAGS=--no-print-directory export MAKEFLAGS=--no-print-directory
......
...@@ -39,19 +39,22 @@ int main(int argc, char *argv[]) ...@@ -39,19 +39,22 @@ int main(int argc, char *argv[])
char path[PATH_MAX]; char path[PATH_MAX];
char buf[64]; char buf[64];
char *cwd; /*
* The original code makes dir to be current working
* directory. But it may be too long in google environment
* for path to be fit into struct sockaddr_un.
* One alternate way to resolve it is to use relative path
* for sockaddr_un, but criu has not supported relative
* bind path yet.
* We change it to "/tmp" to ensure its short length.
*/
char *dirname = "/tmp";
int ret; int ret;
test_init(argc, argv); test_init(argc, argv);
cwd = get_current_dir_name(); snprintf(path, sizeof(path), "%s/%s", dirname, filename);
if (!cwd) {
fail("getcwd\n");
exit(1);
}
snprintf(path, sizeof(path), "%s/%s", cwd, filename);
unlink(path); unlink(path);
sk_dgram_bound_client = socket(AF_UNIX, SOCK_DGRAM, 0); sk_dgram_bound_client = socket(AF_UNIX, SOCK_DGRAM, 0);
...@@ -71,7 +74,7 @@ int main(int argc, char *argv[]) ...@@ -71,7 +74,7 @@ int main(int argc, char *argv[])
exit(1); exit(1);
} }
snprintf(path, sizeof(path), "%s/%s.bound", cwd, filename); snprintf(path, sizeof(path), "%s/%s.bound", dirname, filename);
unlink(path); unlink(path);
if (strlen(path) >= sizeof(name_bound.sun_path)) { if (strlen(path) >= sizeof(name_bound.sun_path)) {
fail("too long path"); fail("too long path");
...@@ -81,7 +84,7 @@ int main(int argc, char *argv[]) ...@@ -81,7 +84,7 @@ int main(int argc, char *argv[])
name_bound.sun_family = AF_UNIX; name_bound.sun_family = AF_UNIX;
strncpy(name_bound.sun_path, path, sizeof(name_bound.sun_path)); strncpy(name_bound.sun_path, path, sizeof(name_bound.sun_path));
snprintf(path, sizeof(path), "%s/%s.conn", cwd, filename); snprintf(path, sizeof(path), "%s/%s.conn", dirname, filename);
unlink(path); unlink(path);
if (strlen(path) >= sizeof(name_conn.sun_path)) { if (strlen(path) >= sizeof(name_conn.sun_path)) {
fail("too long path"); fail("too long path");
...@@ -91,7 +94,7 @@ int main(int argc, char *argv[]) ...@@ -91,7 +94,7 @@ int main(int argc, char *argv[])
name_conn.sun_family = AF_UNIX; name_conn.sun_family = AF_UNIX;
strncpy(name_conn.sun_path, path, sizeof(name_conn.sun_path)); strncpy(name_conn.sun_path, path, sizeof(name_conn.sun_path));
snprintf(path, sizeof(path), "%s/%s.bound-conn", cwd, filename); snprintf(path, sizeof(path), "%s/%s.bound-conn", dirname, filename);
unlink(path); unlink(path);
if (strlen(path) >= sizeof(name_bound_conn.sun_path)) { if (strlen(path) >= sizeof(name_bound_conn.sun_path)) {
fail("too long path"); fail("too long path");
...@@ -198,5 +201,12 @@ int main(int argc, char *argv[]) ...@@ -198,5 +201,12 @@ int main(int argc, char *argv[])
test_msg("dgram-bound-conn : '%s'\n", buf); test_msg("dgram-bound-conn : '%s'\n", buf);
pass(); pass();
/*
* Do cleanup work
*/
unlink(name_bound.sun_path);
unlink(name_conn.sun_path);
unlink(name_bound_conn.sun_path);
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment