[CRIU] [PATCH 04/18] zdtm: Send two descriptors in two SCMs

Pavel Emelyanov xemul at virtuozzo.com
Mon Jul 10 12:38:36 MSK 2017


Only the send code is altered, as upon receiving kernel
merges all scm_rights int one. CRIU relies on this merge
and this is to catch situations if the kernel suddenly 
stops doing this.

Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 test/zdtm/static/Makefile   |  2 ++
 test/zdtm/static/scm03.c    | 31 +++++++++++++++++++++++++++++--
 test/zdtm/static/scm04.c    |  1 +
 test/zdtm/static/scm04.desc |  1 +
 4 files changed, 33 insertions(+), 2 deletions(-)
 create mode 120000 test/zdtm/static/scm04.c
 create mode 100644 test/zdtm/static/scm04.desc

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 79963f3..dd77768 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -157,6 +157,7 @@ TST_NOFILE	:=				\
 		scm01				\
 		scm02				\
 		scm03				\
+		scm04				\
 		aio00				\
 		aio01				\
 		fd				\
@@ -447,6 +448,7 @@ sigpending:		LDLIBS += -lrt
 vdso01:			LDLIBS += -lrt
 scm01:			CFLAGS += -DKEEP_SENT_FD
 scm02:			CFLAGS += -DSEND_BOTH
+scm04:			CFLAGS += -DSEPARATE
 mntns_link_remap:	CFLAGS += -DZDTM_LINK_REMAP
 mntns_shared_bind02:	CFLAGS += -DSHARED_BIND02
 mntns_root_bind02:	CFLAGS += -DROOT_BIND02
diff --git a/test/zdtm/static/scm03.c b/test/zdtm/static/scm03.c
index 9e89628..881bdf8 100644
--- a/test/zdtm/static/scm03.c
+++ b/test/zdtm/static/scm03.c
@@ -14,11 +14,30 @@ static int send_fd(int via, int fd1, int fd2)
 	struct msghdr h = {};
 	struct cmsghdr *ch;
 	struct iovec iov;
-	char buf[CMSG_SPACE(2 * sizeof(int))], c = '\0';
+#ifdef SEPARATE
+	char buf[2 * CMSG_SPACE(sizeof(int))];
+#else
+	char buf[CMSG_SPACE(2 * sizeof(int))];
+#endif
+	char c = '\0';
 	int *fdp;
 
 	h.msg_control = buf;
 	h.msg_controllen = sizeof(buf);
+#ifdef SEPARATE
+	ch = CMSG_FIRSTHDR(&h);
+	ch->cmsg_level = SOL_SOCKET;
+	ch->cmsg_type = SCM_RIGHTS;
+	ch->cmsg_len = CMSG_LEN(sizeof(int));
+	fdp = (int *)CMSG_DATA(ch);
+	fdp[0] = fd1;
+	ch = CMSG_NXTHDR(&h, ch);
+	ch->cmsg_level = SOL_SOCKET;
+	ch->cmsg_type = SCM_RIGHTS;
+	ch->cmsg_len = CMSG_LEN(sizeof(int));
+	fdp = (int *)CMSG_DATA(ch);
+	fdp[0] = fd2;
+#else
 	ch = CMSG_FIRSTHDR(&h);
 	ch->cmsg_level = SOL_SOCKET;
 	ch->cmsg_type = SCM_RIGHTS;
@@ -26,6 +45,7 @@ static int send_fd(int via, int fd1, int fd2)
 	fdp = (int *)CMSG_DATA(ch);
 	fdp[0] = fd1;
 	fdp[1] = fd2;
+#endif
 	h.msg_iov = &iov;
 	h.msg_iovlen = 1;
 	iov.iov_base = &c;
@@ -42,7 +62,8 @@ static int recv_fd(int via, int *fd1, int *fd2)
 	struct msghdr h = {};
 	struct cmsghdr *ch;
 	struct iovec iov;
-	char buf[CMSG_SPACE(2 * sizeof(int))], c;
+	char buf[CMSG_SPACE(2 * sizeof(int))];
+	char c;
 	int *fdp;
 
 	h.msg_control = buf;
@@ -55,6 +76,12 @@ static int recv_fd(int via, int *fd1, int *fd2)
 	if (recvmsg(via, &h, 0) <= 0)
 		return -1;
 
+	if (h.msg_flags & MSG_CTRUNC) {
+		test_msg("CTR\n");
+		return -2;
+	}
+
+	/* No 2 SCM-s here, kernel merges them upon send */
 	ch = CMSG_FIRSTHDR(&h);
 	if (h.msg_flags & MSG_TRUNC)
 		return -2;
diff --git a/test/zdtm/static/scm04.c b/test/zdtm/static/scm04.c
new file mode 120000
index 0000000..f1f86dd
--- /dev/null
+++ b/test/zdtm/static/scm04.c
@@ -0,0 +1 @@
+scm03.c
\ No newline at end of file
diff --git a/test/zdtm/static/scm04.desc b/test/zdtm/static/scm04.desc
new file mode 100644
index 0000000..ded8987
--- /dev/null
+++ b/test/zdtm/static/scm04.desc
@@ -0,0 +1 @@
+{'flags': 'crfail'}
-- 
2.1.4



More information about the CRIU mailing list