[CRIU] [PATCH] zdtm: one more test case for controlling terminals

Andrey Vagin avagin at openvz.org
Mon Mar 18 17:42:56 EDT 2013


  PID   SID TT       COMMAND
26748 26748 ?        tty03
26749 26749 pts/2     \_ tty03
26750 26750 ?             \_ tty03

The second process has not a file descriptor for the ctl tty,
but this tty is opened in tty03.

Currently CRIU can not restore this test case correctly.

Cc: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/zdtm/live/static/Makefile |   1 +
 test/zdtm/live/static/tty03.c  | 114 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+)
 create mode 100644 test/zdtm/live/static/tty03.c

diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 9bc0936..76b6c7c 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -80,6 +80,7 @@ TST_NOFILE	=				\
 		pty04				\
 		tty00				\
 		tty02				\
+		tty03				\
 		mountpoints			\
 		netns				\
 		session01			\
diff --git a/test/zdtm/live/static/tty03.c b/test/zdtm/live/static/tty03.c
new file mode 100644
index 0000000..e66125e
--- /dev/null
+++ b/test/zdtm/live/static/tty03.c
@@ -0,0 +1,114 @@
+#define _XOPEN_SOURCE
+#include <stdlib.h>
+#include "zdtmtst.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+
+const char *test_doc	= "Check a controlling terminal, if a proper fd belongs to another session leader";
+const char *test_author	= "Andrey Vagin <avagin at openvz.org>";
+
+int main(int argc, char ** argv)
+{
+	int fdm, fds, exit_code = 1, status;
+	char *slavename;
+	pid_t sid_b, sid_a, pid;
+	int pfd[2];
+
+	test_init(argc, argv);
+
+	if (pipe(pfd) == -1) {
+		err("pipe");
+		return 1;
+	}
+
+	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);
+
+	pid = test_fork();
+	if (pid == 0) {
+		if (setsid() == -1) {
+			err("setsid");
+			return 1;
+		}
+
+		close(pfd[0]);
+
+		/* set up a controlling terminal */
+		fds = open(slavename, O_RDWR | O_NOCTTY);
+		if (fds == -1) {
+			err("Can't open a slave pseudoterminal %s", slavename);
+			return 1;
+		}
+		ioctl(fds, TIOCSCTTY, 1);
+
+		pid = test_fork();
+		if (pid == 0) {
+			if (setsid() == -1) {
+				err("setsid");
+				return 1;
+			}
+
+			close(pfd[1]);
+
+			test_waitsig();
+			exit(0);
+		}
+
+		close(fds);
+		close(pfd[1]);
+
+		test_waitsig();
+
+		kill(pid, SIGTERM);
+		wait(&status);
+
+		exit(status);
+	}
+
+	close(pfd[1]);
+	if (read(pfd[0], &sid_a, 1) != 0) {
+		err("read");
+		goto out;
+	}
+
+	if (ioctl(fdm, TIOCGSID, &sid_b) == -1) {
+		err("The tty is not a controlling");
+		goto out;
+	}
+
+	test_daemon();
+	test_waitsig();
+
+	if (ioctl(fdm, TIOCGSID, &sid_a) == -1) {
+		fail("The tty is not a controlling");
+		goto out;
+	}
+
+	if (sid_b != sid_a) {
+		fail("The tty is controlling for someon else");
+		goto out;
+	}
+
+	exit_code = 0;
+
+out:
+	kill(pid, SIGTERM);
+	wait(&status);
+
+	if (status == 0 && exit_code == 0)
+		pass();
+
+	return exit_code;
+}
-- 
1.7.11.7



More information about the CRIU mailing list