[CRIU] [PATCH] zdtm: check a non-controlling terminal
Andrey Vagin
avagin at openvz.org
Mon Oct 29 12:54:39 EDT 2012
---
test/zdtm/live/static/Makefile | 1 +
test/zdtm/live/static/tty02.c | 66 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+)
create mode 100644 test/zdtm/live/static/tty02.c
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 03e40fe..013d0f6 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -66,6 +66,7 @@ TST_NOFILE = \
pty03 \
pty04 \
tty00 \
+ tty02 \
mountpoints \
netns \
session01 \
diff --git a/test/zdtm/live/static/tty02.c b/test/zdtm/live/static/tty02.c
new file mode 100644
index 0000000..3d73f89
--- /dev/null
+++ b/test/zdtm/live/static/tty02.c
@@ -0,0 +1,66 @@
+#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 a non-controling terminal";
+const char *test_author = "Andrey Vagin <avagin at openvz.org>";
+
+static void sighup_handler(int signo)
+{
+ test_msg("SIGHUP is here\n");
+}
+
+int main(int argc, char ** argv)
+{
+ int fdm, fds;
+ char *slavename;
+ pid_t sid;
+
+ test_init(argc, argv);
+
+ signal(SIGHUP, sighup_handler);
+
+ setsid();
+
+ 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);
+
+ /* 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, TIOCNOTTY)) {
+ err("Unable to detach a terminal");
+ return 1;
+ }
+
+ test_daemon();
+ test_waitsig();
+
+ if (ioctl(fds, TIOCGSID, &sid) != -1 || errno != ENOTTY) {
+ fail("The tty is a controlling for someone");
+ return 1;
+ }
+
+ pass();
+
+ return 0;
+}
--
1.7.11.7
More information about the CRIU
mailing list