Commit ef726ad5 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

zdtm: one more test case for controlling terminals

  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@openvz.org>
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent f2664d65
...@@ -80,6 +80,7 @@ TST_NOFILE = \ ...@@ -80,6 +80,7 @@ TST_NOFILE = \
pty04 \ pty04 \
tty00 \ tty00 \
tty02 \ tty02 \
tty03 \
mountpoints \ mountpoints \
netns \ netns \
session01 \ session01 \
......
#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@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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment