sk: Support SO_NO_CHECK option

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tty: Make tty_setup_slavery to return error

In case if here no task found which would restore
controlling terminal -- exit with error instead of
continue with just error message.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
syscalls: Add sys_ioctl

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Add parasite_dump_tty helper

Will need it to fetch tty link parameters. This is
because the kernel provides SID/PGID related to the
caller context, and if we're dumping the process inside
namespace -- we need local SID/PGIDs, not global ones.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Make struct fd_parms to carry @parasite_ctl pointer

Some file-type specific parameters can be fetched with
parasite code only, so lets carry parasite control block
pointer in struct fd_parms.

This is a bit ugly but requires less code to touch and
enough for now. In long terms we need some more generalized
routine/hooks which would depends on file type.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tty: Drop sid/pgid test from verify_info

Since we've started fetching sid/pgid from the
dumpee context we're allowed to obtain sid/pgid
on a slave peer. This is perfectly valid. So
drop this test.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Make parasite_args helper global

Will need it in tty layer.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tty: Make tty_get_sid_pgrp() to use parasite code

We need to use namespace local sid/pgid parameters
assigned on tty link, thus use parasite helper.

Otherwise we might fail on restoring controlling
terminal inside namespace (though everything else
will work even without this patch).

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tty: Sanitize tty parasite-side dumping

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
core: Support task scheduler policies and priorities

No magic here, just fetch info using getpriority and sched_getxxx calls.
Good news is that the mentioned syscalls take pid as argument and do work
with it, i.e. -- no need in parasite help here.

Restore is splitted into prep -- copy sched bits from image on restorer
args -- and the restore itself. It's done to avoid restoring tasks info
with IDLE priority ;) To make restorer not-fail sched bits are validated
for sanity on prep stage.

Minimal sanity test is also there.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
types: use siginfo_t from signal.h for rt_signalfn_t declaration

It should fit the sa_sigaction declaration, otherwise compiler
complains about uncasted assignments.

 | restorer.c: In function тАШ__export_restore_taskтАЩ:
 | restorer.c:318:20: error: assignment from incompatible pointer type [-Werror]

So just use siginfo_t here from the system signal.h header.

Signed-off-by: Andrew Grigorev <andrew@ei-grad.ru>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restorer: Add sys/resource.h header

Otherwise PRIO_PROCESS may be not found.

Reported-by: Andrew Grigorev <andrew@ei-grad.ru>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
sfd_type: Add SELF_STDIN_OFF service fd and call helpers where needed

We will need it for slave ttys migration. They serve for one purpose --
to clone self stdio descriptor and use it with tty layer, which will
be addressed in further patches.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
options: Add "--shell-job" option

This option will tells the tool to procceed dumping
even if a root task is not a session leader.

This implies that this option will allow to "migrate"
one external tty connection. Say a person may dump
"top" application in one bash shell and restore it
in another shell session.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
pstree: Allow to dump and restore session non-leaders if --shell-job passed

If --shell-job passed we allow to dump and restpre session non-leaders.

Note that in sake of tty restore (which will be addressed in
further patches) we do inherit process group for root task.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tty: Mark collected tty in @tty_active_pairs bitmap

Upon reception of tty we need to mark it in @tty_active_pairs
bitmam thus we will be able to verify if

 - all active ttys obtained are paired
 - if not paired then only one external tty is allowed

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tty: Update tty verification procedure

We need to make sure that the only one external tty
is present, since otherwise we have no idea on which
pts index to connect them on restore.

This patch extends tty_verify_active_pairs procedure to
count how many external tty is present in the dump image.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tty, restore: Migrate tty slave peer connection if --shell-job passed

In case if we've dumped a slave peer only (say a user dumped `top'
application) we should migrate it on current active terminal, which
barely an own standart stream prepared for us by the file engine.

Note only one external slave peer is allowed simply because
otherwise we can't distinguish which indices should be used
for each of them.

The patch basically does the following things

 - Check if the SID present on peer exist in current
   process tree, we need to be sure that we can restore
   peer parameters and controlling terminal if present

 - Rename pty_open_fake_ptmx to pty_open_unpaired_slave
   because we might be inheriting SELF_STDIN_OFF instead
   of opening fake master peer

 - Do inherit SELF_STDIN_OFF and restore tty group if
   we are restoring external tty

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
docs: Update documentation

 - Drop -c option from "dump" context,
   it is no longer valid

 - Add --link-remap, --shell-job options

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
net: Split dump_links into part

We'll need to dump links for another purpose, so prepare the
generic rtnl talker for that.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>