[CRIU] [PATCH] zdtm: check a control terminal can be restored without a proper session leader

Andrey Vagin avagin at openvz.org
Mon Oct 29 10:59:58 EDT 2012


---
 sk-unix.c                           |   7 --
 test/zdtm.sh                        |   4 ++
 test/zdtm/live/static/Makefile      |   1 +
 test/zdtm/live/static/mountpoints.c |   2 +-
 test/zdtm/live/static/tty01.c       | 127 ++++++++++++++++++++++++++++++++++++
 5 files changed, 133 insertions(+), 8 deletions(-)
 create mode 100644 test/zdtm/live/static/tty01.c

diff --git a/sk-unix.c b/sk-unix.c
index 8da7ac4..bf2d133 100644
--- a/sk-unix.c
+++ b/sk-unix.c
@@ -92,15 +92,8 @@ static int can_dump_unix_sk(const struct unix_sk_desc *sk)
 
 	switch (sk->state) {
 	case TCP_LISTEN:
-		break;
 	case TCP_ESTABLISHED:
-		break;
 	case TCP_CLOSE:
-		if (sk->type != SOCK_DGRAM) {
-			pr_err("Unexpected state %d on type %d\n",
-				sk->state, sk->type);
-			return 0;
-		}
 		break;
 	default:
 		pr_err("Unknown state %d\n", sk->state);
diff --git a/test/zdtm.sh b/test/zdtm.sh
index fbc009c..e1a0755 100644
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -243,6 +243,8 @@ EOF
 	mkdir -p $ddump
 
 	save_fds $PID  $ddump/dump.fd
+	ps axf > $ddump/ps.before
+read
 	setsid $CRTOOLS dump --tcp-established --link-remap -x --evasive-devices -D $ddump -o dump.log -v 4 -t $PID $args $ARGS || {
 		echo WARNING: process $tname is left running for your debugging needs
 		return 1
@@ -269,6 +271,8 @@ EOF
 		echo Restore $PID
 		setsid $CRTOOLS restore --tcp-established -x -D $ddump -o restore.log -v 4 -d -t $PID $args || return 2
 
+		ps axf > $ddump/ps.after
+
 		for i in `seq 5`; do
 			save_fds $PID  $ddump/restore.fd
 			diff_fds $ddump/dump.fd $ddump/restore.fd && break
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 03e40fe..a01fc0a 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -66,6 +66,7 @@ TST_NOFILE	=				\
 		pty03				\
 		pty04				\
 		tty00				\
+		tty01				\
 		mountpoints			\
 		netns				\
 		session01			\
diff --git a/test/zdtm/live/static/mountpoints.c b/test/zdtm/live/static/mountpoints.c
index f1d35dd..4c3ce9c 100644
--- a/test/zdtm/live/static/mountpoints.c
+++ b/test/zdtm/live/static/mountpoints.c
@@ -87,7 +87,7 @@ done:
 	}
 	if (mount("none", MPTS_ROOT"/kernel/sys/fs/binfmt_misc",
 					"binfmt_misc", 0, "") < 0) {
-		fail("Can't mount proc");
+		fail("Can't mount binfmt_misc");
 		return 1;
 	}
 
diff --git a/test/zdtm/live/static/tty01.c b/test/zdtm/live/static/tty01.c
new file mode 100644
index 0000000..8b7da0e
--- /dev/null
+++ b/test/zdtm/live/static/tty01.c
@@ -0,0 +1,127 @@
+#define _XOPEN_SOURCE
+#include <stdlib.h>
+#include "zdtmtst.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+
+const char *test_doc	= "Check that a control terminal is restored,"
+				"if a proper session leader is absent.";
+const char *test_author	= "Andrey Vagin <avagin at openvz.org>";
+
+static int sighup = 0;
+static void sighup_handler(int signo)
+{
+	test_msg("SIGHUP is here\n");
+	sighup = 1;
+}
+
+int main(int argc, char ** argv)
+{
+	int fdm, fds, status;
+	char *slavename;
+	pid_t pid;
+	int p[2];
+
+	test_init(argc, argv);
+
+	fdm = open("/dev/ptmx", O_RDWR);
+	if (fdm == -1) {
+		err("Can't open a master pseudoterminal");
+		return 1;
+	}
+
+	grantpt(fdm);
+	unlockpt(fdm);
+	slavename = ptsname(fdm);
+
+	if (pipe(p) == -1) {
+		err("Unable to create a pipe");
+		return -1;
+	}
+
+	pid = test_fork();
+	if (pid < 0) {
+		err("fork() failed");
+		return 1;
+	}
+
+	if (pid == 0) {
+		close(fdm);
+		close(p[0]);
+
+		if (setsid() == -1)
+			return 1;
+
+		/* set up a controlling terminal */
+		fds = open(slavename, O_RDWR);
+		if (fds == -1) {
+			err("Can't open a slave pseudoterminal %s", slavename);
+			return 1;
+		}
+
+		if (ioctl(fds, TIOCSCTTY, 1) < 0) {
+			err("Can't setup a controlling terminal");
+			return 1;
+		}
+		close(fds);
+
+		pid = test_fork();
+		if (pid < 0)
+			return -1;
+
+		if (pid > 0) {
+			if (write(p[1], &pid, sizeof(pid)) != sizeof(pid)) {
+				err("Could not send a pid");
+				return 1;
+			}
+			return 0;
+		}
+		close(p[1]);
+	
+		signal(SIGHUP, sighup_handler);
+
+		test_waitsig();
+		if (sighup)
+			return 0;
+		return 1;
+	}
+
+	close(p[1]);
+
+	test_daemon();
+
+	pid = waitpid(pid, &status, 0);
+	if (pid < 0)
+		return 1;
+
+	if (WIFEXITED(status)) {
+		if (WEXITSTATUS(status)) {
+			fail("The child returned %d", WEXITSTATUS(status));
+			return 1;
+		}
+	} else {
+		err("The child has been killed by %d", WTERMSIG(status));
+		return 1;
+	}
+
+	if (read(p[0], &pid, sizeof(pid)) != sizeof(pid)) {
+		err("Could not get a pid");
+		return 1;
+	}
+
+	test_waitsig();
+
+	close(fdm);
+
+	kill(pid, SIGTERM);
+
+	pass();
+
+	return 0;
+}
-- 
1.7.11.7



More information about the CRIU mailing list