[02/18] zdtm: Send two descriptors via unix socket

Submitted by Pavel Emelyanov on July 10, 2017, 9:38 a.m.

Details

Message ID 2fc0ae63-8961-c696-8ca4-2d09c7373357@virtuozzo.com
State New
Series "Support descriptors sent over unix sockets"
Headers show

Commit Message

Pavel Emelyanov July 10, 2017, 9:38 a.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 test/zdtm/static/Makefile   |  2 ++
 test/zdtm/static/scm00.c    | 20 +++++++++++++++++++-
 test/zdtm/static/scm02.c    |  1 +
 test/zdtm/static/scm02.desc |  1 +
 4 files changed, 23 insertions(+), 1 deletion(-)
 create mode 120000 test/zdtm/static/scm02.c
 create mode 100644 test/zdtm/static/scm02.desc

Patch hide | download patch | download mbox

diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index 661ff7f..f0c0c17 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -155,6 +155,7 @@  TST_NOFILE	:=				\
 		remap_dead_pid_root			\
 		scm00				\
 		scm01				\
+		scm02				\
 		aio00				\
 		aio01				\
 		fd				\
@@ -444,6 +445,7 @@  mnt_ext_manual:		CFLAGS += -D ZDTM_EXTMAP_MANUAL
 sigpending:		LDLIBS += -lrt
 vdso01:			LDLIBS += -lrt
 scm01:			CFLAGS += -DKEEP_SENT_FD
+scm02:			CFLAGS += -DSEND_BOTH
 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/scm00.c b/test/zdtm/static/scm00.c
index 39c1473..de626d9 100644
--- a/test/zdtm/static/scm00.c
+++ b/test/zdtm/static/scm00.c
@@ -91,13 +91,21 @@  int main(int argc, char **argv)
 
 #ifndef KEEP_SENT_FD
 	close(p[0]);
-
+#ifdef SEND_BOTH
+	if (send_fd(sk[0], p[1]) < 0) {
+		pr_perror("Can't send 2nd descriptor");
+		exit(1);
+	}
+	close(p[1]);
+	p[0] = p[1] = -1;
+#else
 	/* Swap pipe ends to make scm recv put pipe into different place */
 	dup2(p[1], p[0]);
 	close(p[1]);
 	p[1] = p[0];
 	p[0] = -1;
 #endif
+#endif
 
 	test_daemon();
 	test_waitsig();
@@ -107,6 +115,16 @@  int main(int argc, char **argv)
 		fail("Can't recv pipe back (%d)", p[0]);
 		goto out;
 	}
+
+#ifdef SEND_BOTH
+	test_msg("Recv 2nd end\n");
+	p[1] = recv_fd(sk[1]);
+	if (p[1] < 0) {
+		fail("Can't recv 2nd pipe back (%d)", p[1]);
+		goto out;
+	}
+#endif
+
 #ifdef KEEP_SENT_FD
 	if (rfd == p[0]) {
 		fail("Original descriptor not kept");
diff --git a/test/zdtm/static/scm02.c b/test/zdtm/static/scm02.c
new file mode 120000
index 0000000..4cab0ed
--- /dev/null
+++ b/test/zdtm/static/scm02.c
@@ -0,0 +1 @@ 
+scm00.c
\ No newline at end of file
diff --git a/test/zdtm/static/scm02.desc b/test/zdtm/static/scm02.desc
new file mode 100644
index 0000000..ded8987
--- /dev/null
+++ b/test/zdtm/static/scm02.desc
@@ -0,0 +1 @@ 
+{'flags': 'crfail'}