Commit graph

113 commits

Author SHA1 Message Date
Dmitry Safonov
3a244a0d1f criu: tty: pick only master as a control terminal
tty_find_restoring_task will prepare control terminal (by tcsetpgrp)
only if tty is master.
By a chance it's possible to pick slave terminal as a control, which
will refrain restoring control terminal.

https://jira.sw.ru/browse/PSBM-42093

Signed-off-by: Dmitry Safonov <dsafonov@odin.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-12-11 16:50:12 +03:00
Andrew Vagin
1a86283bfb tty: open all terminals with O_NOCTTY
Otherwise the kernel can set it as a control terminal for the currect
session and CRIU will not be able to set it as a control terminal for
the target process.

Reported-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-17 10:48:56 +03:00
Cyrill Gorcunov
04f7131ad3 tty: Restore controlling terminal once per session
There might be several same terminals opened (say
tty6 or whatever) which gonna look as separate
files but actually pointing to the same tty kernel
instance. Moreover if it's a controlling terminal
we will be trying to restore it as many times as
find non zero sid on a peer.

Instead lets do a simple trick first: choose a leader
from a terminal group and use it only for controlling
terminal restoration.

https://jira.sw.ru/browse/PSBM-40969

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Reviewed-by: Andrew Vagin <avagin@odin.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-11-13 20:00:33 +03:00
Tycho Andersen
85ebf0a83b usernsd: also pass pid of process that made the req
We'll use this in the next patch to correctly write sysctls.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-09-21 12:01:01 +03:00
Cyrill Gorcunov
4fd669fca6 tty: Drop TTY_SUBTYPE_SLAVE from /dev/console and /dev/tty
They are confusing code readers. Lets save these @subtypes
for Unix98 pty peers where they are really important.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-02 20:20:23 +03:00
Cyrill Gorcunov
243e58f0e3 tty: Implement support of current tty
Opening current tty is tricky: first slave peer should
be opened and session restored, and only then we can
open /dev/tty. So that I made rst_info to carry
additional list @tty_ctty where all current ttys
get gathered and opened after slave peers were
brought to live.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-02 20:20:08 +03:00
Cyrill Gorcunov
80a134a44b tty: Make sure we're opening unpaired pty
pty_open_unpaired_slave must be called for
pty peers only and it caused no problems so
far but better to be sure it's pty peer we're
restoring (there gonna be more drivers with
time).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-02 20:20:07 +03:00
Cyrill Gorcunov
e558d58a28 tty: Rename open_pty_reg to open_tty_reg
This is not pty specific routine but rather a common one.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-02 20:20:03 +03:00
Cyrill Gorcunov
25abdf3ac4 tty: Rework tty_driver structure
- rename @t to @type and use protobuf constants here instead
 - for special features use @subtype just like kernel does
 - get rid of TTY_TYPE_ constants, we don't need them
 - drop @flags, we don't need it anymore

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-02 20:20:01 +03:00
Pavel Emelyanov
e29c9daec2 img: Remove O_OPT and COLLECT_OPTIONAL
Current code doesn't make any difference between OPT and no-OPT
except for the message is printed or not in the open_image().
So this particular change changes nothing but the availability of
this message.

In the next patches I wil introduce "empty images" to deal with
the ENOENT situation in a more graceful manner.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-13 14:42:01 +03:00
Cyrill Gorcunov
290211fb94 tty: Aligh tty_driver members
As done for other structures here in file.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-10 21:16:40 +03:00
Cyrill Gorcunov
19948472d9 tty: Rename tty_type to tty_driver
There are too many "type" in code.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-10 21:16:22 +03:00
Cyrill Gorcunov
819f41eaa5 tty: Drop dangling \Tab
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-10 21:16:15 +03:00
Pavel Emelyanov
48032d8780 tty: Introduce TTY_MASTER flag
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:47:40 +03:00
Pavel Emelyanov
bc535380de tty: Sanitize ctl terminal restore codeflow
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:47:38 +03:00
Pavel Emelyanov
d47975b5ec tty: Move image type onto tty_type
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:47:36 +03:00
Pavel Emelyanov
3b913082ac tty: Introduce per-type flags
And start making and using the TTY_PAIR one.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:47:34 +03:00
Pavel Emelyanov
a7631ed8f9 tty: Put open() callback on tty_type
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:47:09 +03:00
Pavel Emelyanov
c314ffbe69 tty: Per-type img_get_index callback
This one is used on restore (and for static indices
the constant value is used too).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:47:08 +03:00
Pavel Emelyanov
bced873181 tty: Per-type fd_get_index callback
This one gets index from fd/fd_parms pair on dump. For
console and vt the index is constant and just sits on
the tty_type (will also be used on restore, see next
patch).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:47:07 +03:00
Pavel Emelyanov
a9ae0ab6d9 tty: Put tty name on tty_type
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:47:06 +03:00
Pavel Emelyanov
057f00ce92 tty: Make tty type be object rather than integer
The plan is to replace tons of if (type == TTY_TYPE_FOO) checks
with type->something dereferences.

To do this, start with replacing int type with struct tty_type *
in relevant places and fixing compilation.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:47:04 +03:00
Pavel Emelyanov
a7601d6a50 tty: Move tty_type() and is_pty() to tty.c
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:46:16 +03:00
Pavel Emelyanov
3a25abdad2 tty: Use tty_name in prints
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-03-04 17:45:08 +03:00
Cyrill Gorcunov
9be7769017 tty: Fix typo in tty_setup_slavery for VT
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-02-20 00:11:47 +03:00
Pavel Emelyanov
7d482de1ca tty: Restore locked termios with usernsd call
Locked termios require global CAP_SYS_ADMIN. But let's
restore everything for tty in one call since regular
termios depend on locked and it's not nice to do sync
usernsd call for locked only.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2015-02-13 16:11:38 +04:00
Pavel Emelyanov
feda34319a tty: Assign empty file_desc_ops to fake file descs
The newer cleanups in fd inherit code need every file-desc
to have non-NULL ops. This hunk was lost in tty code in the
very beginning.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-13 22:19:58 +03:00
Ruslan Kuprieiev
2d91ff5f2e tty:add comment explaining indices, v2
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-12-22 13:48:45 +03:00
Ruslan Kuprieiev
1ace257022 tty: add vt support, v2
/dev/ttyN are the virtual terminals which are provided
by the system with major 4 and minor 1..63.
You can run some program on ttyN by pressing alt+ctrl+FN
and running it manualy or by using open(openvt nowadays).

This patch also allows us to run all our tests from a vt.

v2, style fix + using linux/vt.h for constants

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-12-22 13:48:31 +03:00
Cyrill Gorcunov
4cb9eaf39f tty: Fix compilation warrning
| tty.c: In function ‘tty_restore_ctl_terminal’:
 | include/criu-log.h:42:16: error: ‘index’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

Same time assign CONSOLE_INDEX for debug info.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-30 16:24:15 +04:00
Tycho Andersen
a6e746ba17 tty: don't crash if restoring a non-pty
The pty field here is only present with certain tty types, so we shouldn't
unconditionally dereference it, or criu will hang.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-30 15:14:49 +04:00
Cyrill Gorcunov
ec50bd8c91 tty: Add support of /dev/console
/dev/console is a system console which provided
by the system with major 5 and minor 1. It's usually
configured on system startup with console= option
and underlied driver is resposible to deliver messages
to the console user.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-27 21:35:39 +04:00
Cyrill Gorcunov
a9c724142d tty: Fix path inversion for /dev/pts/ptmx
Need to compare the /pts/ part in the
former path, otherwise it will produce
bogus /dev/pts/pts/index form.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-23 22:14:41 +04:00
Cyrill Gorcunov
caa64d974d tty: Use regular files engine to save paths to the peers, v5
Currently we're using predefined format for master/slave pty peers:
masters are always /dev/ptmx, while slaves are /dev/pts/$index,
where $index is the peer number.

While fitting most of distros this is not always correct and slave peers
might be mounted to an arbitrary place, so that we need to somehow
carry paths with ourself in image.

Instead of bloating current tty image lets use regular file engine instead
and on checkpoint stage save a path to the link in regfiles set, then on
restore simply fetch it from the image.

Such approach will help in future when we need to support multiple
instances of devpts filesystem.

To support backward compatibility with images where no regfile
records are present we generate new one on the fly in
pty_alloc_reg() helper.

Because of the need to restore dead slave peers and restore of
the controlling terminal we need to generate that named "fake
inverted" pty_alloc_fake_reg() helper: in particular if
we need to open dead slave peer we generate fake master peer,
open it and the close out. Almost the same situation in
restoring contolling terminal -- we get master peer, generate
appropriate fake slave object, open it, manipulate, then
close it out and free.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-23 17:54:23 +04:00
Cyrill Gorcunov
09aa15c7a3 tty: Parse slave peer index from fd_parms
We will use this path in reg-files engine anyway
so simply switch to this ability now.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-23 17:51:30 +04:00
Cyrill Gorcunov
d6e231ae09 tty: parasite -- Don't call for TIOCGPKT/TIOCGPTLCK on non-ptys
We will have to support more tty types in future so
make calls depending on type of ttys.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-23 17:51:27 +04:00
Cyrill Gorcunov
bcc1f4eb72 tty: Introduce tty types
Instead of calling case() with majors all over the places lets
introduce own enum for tty types and use it instead.

Because we're using not @major numbers now but taking @minors
into account as well, this brings more strict check of which
kind of terminals we can dump now thus it's potentially should
fix the cases when we're trying to c/r terminals which we don't
understand yet (in particular /dev/console [5:1]).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-23 17:51:26 +04:00
Cyrill Gorcunov
bc5fcaa777 tty: collect_one_tty -- Use tty_is_master helper
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-08 18:53:34 +04:00
Cyrill Gorcunov
87418490e5 tty: Rename helpers to reflect the type of peers
- parse_index -> parse_pty_index since it's PTY specific
 - pty_is_master -> tty_is_master because it will test
   not only PTY peers but other types as well
 - pty_is_hung -> tty_is_hung for same reason

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-08 18:52:23 +04:00
Cyrill Gorcunov
d311fd3e46 tty: Add some comments about console and bsd terminals
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-08 18:50:33 +04:00
Cyrill Gorcunov
9b5e050906 tty: Instead of BUG_ON exit out with error early
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-08 18:50:04 +04:00
Cyrill Gorcunov
b708a7d549 tty: Align members in assignments
For readability sake.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-08 18:49:47 +04:00
Pavel Emelyanov
c443b03e10 rst: Rework the rst_info referencing
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-10-01 13:34:38 +04:00
Pavel Emelyanov
5f2a7ac27b img: Rename fdset -> imgset
Since we're going to switch from int-fd-s to class-image
soon the fdset name will not fit into the new terminology.

This patch is

 sed -e 's/fdset/imgset/g' -i *
 sed -e 's/imgset_fd/img_from_set/g' -i *
 git mv include/fdset.h include/imgset.h

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
2014-09-30 21:48:10 +04:00
Andrey Vagin
bff466c291 tty: open tty-s with O_NOCTTY
When we open tty, we don't want to set it as controlling terminal.

[xemul: We do it in all the other places, this one is forgotten.
 The "controlling tty" feature is setup explicitly later with
 the ioctl (TIOCSCTTY) call. ]

This bug was caught by pty04. Where we get unexpected SIGCONT,
which is sent after closing a controlling terminal.

./pty04 --pidfile=pty04.pid --outfile=pty04.out
Dump 9578
Restore
Test: zdtm/live/static/pty04, Result: FAIL
==================================== ERROR ====================================
Test: zdtm/live/static/pty04, Namespace:
Dump log   : /home/jenkins/workspace/Rpi-CRIU/test/dump/static/pty04/9578/1/dump.log
--------------------------------- grep Error ---------------------------------
------------------------------------- END -------------------------------------
Restore log: /home/jenkins/workspace/Rpi-CRIU/test/dump/static/pty04/9578/1/restore.log
--------------------------------- grep Error ---------------------------------
(00.083420) Error (cr-restore.c:1092): 9578 killed by signal 0
(00.083708) Error (cr-restore.c:1713): Restoring FAILED.
------------------------------------- END -------------------------------------
================================= ERROR OVER =================================

Reported-by: Mr Jenkins
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-08-15 13:28:16 +04:00
Pavel Emelyanov
3de41b8070 files: Rework select_ps_list fdsec ops callback
For unlinked opened and mmaped files we'd need to
care about remaps, for this the callback with both
file_desc and fdinfo_list_entry will be required.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-02-05 16:17:59 +04:00
Pavel Emelyanov
20e8d193e5 tty: Print very descriptive message about shell job dump
First thing people typically do with criu is run something
in shell and try to dump it. This is typicall pitfall, as
in that case we face external sid and tty problem. Print a
message on stdout about this and advice wiki page to read.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-12-03 09:59:17 +04:00
Andrey Vagin
dd407dd04e hdrs: minor cleaup
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-07 15:13:50 +04:00
Andrey Vagin
4850fd94a8 crtools: move cr_options in a separate header
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-06 18:17:52 +04:00
Andrey Vagin
1300cf4915 crtools: move all stuff about fdset in a separate header
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-11-06 15:24:48 +04:00