arm: don't use the register R12 in the routine syscall_common()

The register R12 has a special meaning when syscalls are hooked
with ptrace() in ARM that results in a dumpee context corruption
on an injected blob unmap. Note that this patch doesn't solve
the problem entirely since the compiler may corrupt the register
before issuing a call to the routine sys_munmap(); however
we assume that a sufficiently decent compiler doesn't.

Signed-off-by: Alexander Kartashov <alekskartashov@parallels.com>
Tested-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
unix: Print "socket not found" error message on dump

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
unix: Print sockets IDs in hex when collect skips them

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: Support CORK and NODELAY options

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
fs: Reshuffle prepare_fs code flow

Make it ready for root dir restore:
* fix comments
* rename variables
* tune error paths

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rst: Open sys.ns_last_pid before diving into restorer

We restore chroot before doing this, so if we might need to
open one, we may have no access to the /proc/... paths.

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

First of all, this should be done strictly after we've stopped accessing
files by their paths, even absolute. This place is right before going
into restorer.

And the second thing is that we want to re-use the open_fd_by_id engine,
since it handles various tricky cases of open-file-by-path. And since
there's no such thing as fchroot(int fd), we emulate it using the
/proc/self/fd/ links.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: Test for chroot

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: Check that out-of-root file survives

If a task opens a file, then goes chroot, CRIU should still
be able to dump and restore the now-invisible file.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rst: Introduce fine-grained pgid-restore synchronization

We can restore task's pgid which is not equal to its pid,
only when the respective group leader is alive. To make
restore reliable we wait for all group leaders to restore
using separate restore stage.

It's better to optimize this -- each task has a pointer on
its group leader and waits for one to become such.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rst: Don't fail if task entries unmap fail

We cannot fail at that late stage, as everything is restored
and running. In the worst case (unmap fails) restored task would
have one extra mapping.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
rst: Create posix timers earlier

No failures should occur after sigchld restore.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mnt: Collect mntns root from criu, in case we don't dump mount namespace

In case criu and dumpee live in the same mount namespace there's no
need in getting ns' root from init task. We can get it from criu and
(!) void the root == "/" check, required for namespace case.

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

Everything in the sk-unix.c is ready for seq-packet sockets.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: add a comment why we can safly trap task on sigreturn

The kernel notifies about leaving syscall before starting to deliver
signals. If you don't believe me, pls look at arch/x86/kernel/entry_64.S:

int_ret_from_sys_call
        syscall_trace_leave
        do_notify_resume

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: transfer pstree_item in dump_task_core_all

Currently we take pid and core from it and we are going to take state.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Add comment saying why we dump zombies separately from alive tasks

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
crtoools: add support of stopped tasks (v2)

Currently we catch processes on the exit point from sigreturn.
If a task must be restored in the stopped state, we can send SIGSTOP
before detaching from it.

v2: add more descriptive comment about skipping SIGSTOP in ptrace.c
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: check, that stopped tasks are restored correctly

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
images: export cr_fdset_open

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>