zdtm: Add pty01 test

Two slaves on same pty.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
zdtm: Add pty02 test

The test is tricky -- it opens master in task 1
and dup it in task 2, then close in task 1 and
do C/R.

Thus we need to setup SID of master terminal
somehow in children, which usually fails in
currnt tty restore implementation.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
zdtm: Add pty03 test

Non-opened control terminal

* Set a control terminal
* Close a file descriptor on it
* Dump/restore
* Open the control terminal (/dev/tty)
* Check, that it connected to the master end

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
zdtm: Add pty04 test

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
app-test: check screen application

Add test for screen c/r.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
files: Add a few missing brackets

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
tty: Prepare some members for tty merge

This commit introduce some service members
which will be used in future commit. This is
done to simplify overall patching procedure
and bisection.

In particular, we introduce

 - TTY file type, we will need to to describe
   tty file entries

 - CTL_TTY_OFF service fd. This fd will help us
   to create control terminal. We need a special fd
   number for it, because control terminal is to be
   restored in context of a process which sid matches
   the terminal has.

 - ctl_tty_id, this id will carry the control terminal
   id bound to the process which sid matches. The key is
   the following: CTL_TTY_OFF fd stacked on process item
   which has ctl_tty_id set thus file engine will restore
   contol terminal in proper task context.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Add separate lists for master/slave fd on restore

When we will be restoring ttys we need that restore
procedure for master peers will be yielded earlier
than for slave peers due to ttys specifics. With this
commit we introduce @tty_masters and @tty_slaves
lists which will allow us to order tty file restore
procesure.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
tty: Add checkpoint/restore for unix terminals

Usually the PTYs represent a pair of links -- master peer and slave
peer. Master peer must be opened before slave. Internally, when kernel
creates master peer it also generates a slave interface in a form of
/dev/pts/N, where N is that named pty "index". Master/slave connection
unambiguously identified by this index.

Still, one master can carry multiple slaves -- for example a user opens
one master via /dev/ptmx and appropriate /dev/pts/N in sequence.
The result will be the following

master
`- slave 1
`- slave 2

both slave will have same master index but different file descriptors.
Still inside the kernel pty parameters are same for both slaves. Thus
only one slave parameters should be restored, there is no need to carry
all parameters for every slave peer we've found.

Control terminals checkpoint and restore procedure deserves a separate
comments section. Control terminal is seting up on a slave peer but the
task which setups it must have same SID as terminal has, otherwise the
procedure will fail. Note that control terminal is restored via ioctl
on /dev/pts/N, where N is the number of the terminal we need. So we
do a trick here

- during checkpoint we generate the control terminal record written
  into tty image file with unique id, this guarantee us that noone
  else will use this id over all id space

- at restore time we generate a service file desciptor which id get
  assigned from dumped control terminal described above. So once
  file engine finds this service fd we call ioctl on it and viola
  the control terminal is restored.

Not yet addressed problems:

- Also there is a second hardness with slave peers -- at moment of
  restore the master end might be already closed for any reason so
  to resolve such problem we open a fake master peer with proper index
  and hook a slave on it, then we close master peer.

- Find a way to fetch tty flags from the kernel (locked/exclusive)
  and save it in tty_flags.

- Need to figure out how to deal with ttys which have some
  data in buffers not yet flushed, at moment this data will
  be simply lost during c/r

- We might need an additional option which would try to open
  tty with specified index until success instead of exiting
  with error if more than 32 attempts were done, patching
  kernel is not the option here since we can't break ABI
  the kernel provides at moment

[ avagin@:
   - contol terminals restoration code complete rework
   - overall code redesign and simplification
]

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
tty: Add restoration of locked/exclusive ptys

Since opening locked/exclusive ptys do return
different error code we can figure out what
exactly tty flag the peer has.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
zdtm: Add tty05 test

For testing locked/exclusive ptys

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>