[CRIU] [PATCH] test/zdtm/sockets_dgram: Use shorter pathname to support struct sockaddr_un

Yicheng Qin yichengq at google.com
Tue Aug 6 17:43:09 EDT 2013


From: Yicheng Qin <yichengq at google.com>
Subject: [PATCH] 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: Yicheng Qin <yichengq at google.com>
---
 test/zdtm.sh                          |  5 +++++
 test/zdtm/live/static/sockets_dgram.c | 32 +++++++++++++++++++++-----------
 2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/test/zdtm.sh b/test/zdtm.sh
index 98eb075..f640cd7 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -223,6 +223,7 @@ construct_root()
  local ps_path=`type -P ps`
  local libdir=$root/lib
  local libdir2=$root/lib64
+ local tmpdir=$root/tmp

  mkdir -p $root/bin
  cp $ps_path $root/bin
@@ -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/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
+
+ # make 'tmp' dir under new root
+ mkdir $tmpdir
+ chmod 0777 $tmpdir
 }

 export MAKEFLAGS=--no-print-directory
diff --git a/test/zdtm/live/static/sockets_dgram.c
b/test/zdtm/live/static/sockets_dgram.c
index 1df0570..6bdb857 100644
--- a/test/zdtm/live/static/sockets_dgram.c
+++ b/test/zdtm/live/static/sockets_dgram.c
@@ -39,19 +39,22 @@ int main(int argc, char *argv[])

  char path[PATH_MAX];
  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;

  test_init(argc, argv);

- cwd = get_current_dir_name();
- if (!cwd) {
- fail("getcwd\n");
- exit(1);
- }
-
- snprintf(path, sizeof(path), "%s/%s", cwd, filename);
+ snprintf(path, sizeof(path), "%s/%s", dirname, filename);
  unlink(path);

  sk_dgram_bound_client = socket(AF_UNIX, SOCK_DGRAM, 0);
@@ -71,7 +74,7 @@ int main(int argc, char *argv[])
  exit(1);
  }

- snprintf(path, sizeof(path), "%s/%s.bound", cwd, filename);
+ snprintf(path, sizeof(path), "%s/%s.bound", dirname, filename);
  unlink(path);
  if (strlen(path) >= sizeof(name_bound.sun_path)) {
  fail("too long path");
@@ -81,7 +84,7 @@ int main(int argc, char *argv[])
  name_bound.sun_family = AF_UNIX;
  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);
  if (strlen(path) >= sizeof(name_conn.sun_path)) {
  fail("too long path");
@@ -91,7 +94,7 @@ int main(int argc, char *argv[])
  name_conn.sun_family = AF_UNIX;
  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);
  if (strlen(path) >= sizeof(name_bound_conn.sun_path)) {
  fail("too long path");
@@ -198,5 +201,12 @@ int main(int argc, char *argv[])
  test_msg("dgram-bound-conn  : '%s'\n", buf);

  pass();
+
+ /*
+ * Do cleanup work
+ */
+ unlink(name_bound.sun_path);
+ unlink(name_conn.sun_path);
+ unlink(name_bound_conn.sun_path);
  return 0;
 }
-- 
1.8.3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvz.org/pipermail/criu/attachments/20130806/df1e11f2/attachment-0001.html>


More information about the CRIU mailing list