inet: Restore SO_REUSEADDR in case of rollback

tcp_repair_off implicitly modifies SO_REUSEADDR option
inside the kernel (thanks avagin@ for pointing this
feature out) thus if we are to rollback and restore
the former settings of socket -- don't forget to
repair this particular one.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
CC: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
signals: dump alternate stack as misc parameters

The initilization stage is not good for that, because it can fail.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
check: check PTRACE_{GET,SET}SIGMASK

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: move code about creating control sockets in a separate func

It will be used in a few places

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: block signals for each parasite command

Pending signals should be saved, so signals should be blocked.
Signals are blocked for EACH command, because a chance of destroying a
process state should be a small as possible.

At the end there will only two "trapped" commands -- to dump thread
and to start daemon in parasite, so this doesn't add significant
overheads.

If crtools is killed between two commands, a dumped process will run
continue.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: restore registers after each parasite command

Currenly we can restore blocking signals with help ptrace,
so if registers are restored after command, a process state
will not be corrupted if criu crashes.

Same as with previous patch -- at the end there will be only
two trap commands, so this is OK.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: modify process memory only for executing syscalls

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: execute only one parasite commend for dumping per-thread data

We use two commands to get task registers safely. The first command
blocked signals, then crtools dumped registers and all per-thread data
and the the second command unblocks signals.

Currently signals can be blocked with help SETSIGMASK, so we need only
one command to dump per-thread data.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: use only one command for executing parasite in a daemon mode

If a kernel supports PTRACE_SETSIGMASK, criu don't need to execute
PARASITE_CMD_INIT and PARASITE_CMD_DAEMONIZE, because the frist command
is used only for blocking signals. If criu crashes between these
commands, a process state will be corrupted, because all signals remain
blocked.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: typo fix for double pointer on mask of blocked signals

PTRACE_SETSIGMASK takes pointer on mask of blocked signals,
but sigmask is already pointer.

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Facror out common code that runs parasite code

There are 3 users of one -- remote syscall, thread dump and
daemon run.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Sanitize thread dumping code

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Merge thread and task parasite-core info dumping

There are parts dumping which is common to thread and task,
and this stuff is represented by parasite_dump_thread structure.

Merge this into parasite_dump_misc and facror out dumping code.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Add comment why get_task_regs for task is in such a strange place

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Don't push parasite-ctl into fns needing pid only

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
dump: Move signals dumping into a helper

... fixing erroneous goto on error path :)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Reshuffle sync and async daemon-node executing routines

The version, that might not wait for ack is always called with
"async" flag set. Cleanup things according to this.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Rename ack-waiting function to look better

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
v2 criu: Initial skeleton for criu library

Add target lib to Makefile for criu library.
Created directory lib and add there Makefile and criu.c - skelettons for criu library.

Signed-off-by: Ruslan Kupreev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm.sh: dump traffic for *tcpbuf* tests

Sometimes these tests don't pass successfully and we need more
information to investigate the problem.

https://bugzilla.openvz.org/show_bug.cgi?id=2676
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>