[CRIU] [PATCH 3/3] zdtm: check unconnected unix sockets

Andrey Vagin avagin at openvz.org
Thu Nov 1 09:32:20 EDT 2012


https://bugzilla.openvz.org/show_bug.cgi?id=2408

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm.sh                           |  1 +
 test/zdtm/live/static/Makefile         |  1 +
 test/zdtm/live/static/sk-unix-unconn.c | 64 ++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+)
 create mode 100644 test/zdtm/live/static/sk-unix-unconn.c

diff --git a/test/zdtm.sh b/test/zdtm.sh
index fbc004a..a45ef0a 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -39,6 +39,7 @@ static/sock_opts01
 static/sockets_spair
 static/sockets_dgram
 static/socket_queues
+static/sk-unix-unconn
 static/pid00
 static/pstree
 static/cmdlinenv00
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 56ed945..3298c81 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -49,6 +49,7 @@ TST_NOFILE	=				\
 		socket-tcpbuf			\
 		sock_opts00			\
 		sock_opts01			\
+		sk-unix-unconn			\
 		ipc_namespace			\
 		selfexe00			\
 		sem				\
diff --git a/test/zdtm/live/static/sk-unix-unconn.c b/test/zdtm/live/static/sk-unix-unconn.c
new file mode 100644
index 0000000..03c95db
--- /dev/null
+++ b/test/zdtm/live/static/sk-unix-unconn.c
@@ -0,0 +1,64 @@
+#include <unistd.h>
+#include <limits.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include "zdtmtst.h"
+
+const char *test_doc	= "Check unconnected unix sockets";
+const char *test_author	= "Vagin Andrew <avagin at parallels.com>";
+
+int main(int argc, char ** argv)
+{
+	int sk, skc;
+	int ret;
+	char path[PATH_MAX];
+	struct sockaddr_un addr;
+	socklen_t addrlen;
+
+	test_init(argc, argv);
+
+	sk = socket(AF_UNIX, SOCK_STREAM, 0);
+	if (sk == -1) {
+		err("socket\n");
+		return 1;
+	}
+
+	skc = socket(AF_UNIX, SOCK_STREAM, 0);
+	if (skc == -1) {
+		err("socket\n");
+		return 1;
+	}
+
+	snprintf(path, sizeof(path), "X/zdtm-%s-%d", argv[0], getpid());
+
+	addr.sun_family = AF_UNIX;
+	strncpy(addr.sun_path, path, sizeof(addr.sun_path));
+	addrlen = sizeof(addr.sun_family) + strlen(path);
+	addr.sun_path[0] = 0;
+
+	ret = bind(sk, (struct sockaddr *) &addr, addrlen);
+	if (ret) {
+		fail("bind\n");
+		return 1;
+	}
+
+	test_daemon();
+
+	test_waitsig();
+
+	if (listen(sk, 1) == -1) {
+		err("listen");
+		return 1;
+	}
+
+	if (connect(skc, (struct sockaddr *) &addr, addrlen) == -1) {
+		fail("Unable to connect");
+		return 1;
+	}
+
+	pass();
+
+	return 0;
+}
-- 
1.7.11.7



More information about the CRIU mailing list