parasite: wait for any child process

If parasite exited unexpectedly, CRIU gets SIGCHLD and handles it.
In sigchld handler we need to wait any child process.
Currently criu waits neighbours in its group, but a dumped
processes is in another group usually. Here is a typo.

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

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restorer: Compact rst stack evaluation code

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: Iterate tgt vmas by number, not by terminating point

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: Put tgt vmas in rst-mem, not special purpose memory

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: Make optional images check right after open

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Cleanup call to parasite_run when launching daemon

The ctl->sig_blocked in this place is the same as sigframe's one,
as ctl's one was copied into sigframe's few steps before.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: Don't unmap vdso proxy on final cleanup

In case if we need to use vdso proxy the memory area
which holds restorer also has a place for vdso proxy
code itself, so on final pass we should not unmap it,
otherwise any call to vdso function will cause sigsegv.

IOW, the memory before final "cleanup" pass of restorer
might look as

    +-----------+---------+     +-------------+------+
    | bootstrap | rt-vdso | ... | application | vdso |
    +-----------+---------+     +-------------+------+
                       ^                         |
                       `-------------------------+

and we have redirected "vdso" code to jump to "rt-vdso".
After final pass the memory must look as

                +---------+     +-------------+------+
                | rt-vdso | ... | application | vdso |
                +---------+     +-------------+------+
                       ^                         |
                       `-------------------------+

I noticed this problem during container migration
testing, the container itself was suspended on 2.6.32
OpenVZ kernel with apache running inside, and any attempt
to connect to apache caused apache to crash.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Introduce thread_ctx structure

This one keeps registers and sigmask for running thread. Will
be used for simpler parasite management.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Use thread_ctx in thread dumping

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Use thread_ctx in parasite_run/_trap calls

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Introduce get_thread_ctx helper

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Generalize running parasite context

The only place left, that runs parasite by hands -- unmap().
Now we can use parasite_run() for that.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
parasite: Add helper for restoring thread context

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
crtools: add init_opts()

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
service: reinit opts in cr_service_work()

These are inherited from parent on fork(), thus need to put them in
clean state.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restorer: Add missing closing brace in print

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: disable repair mode for sockets on rollback (v2)

Currently if a network namespace is dumped and something fails, sockets
remain in repair mode. It's because cpt_unlock_tcp_connections is
executed only if network namespace is not dumped.

cpt_unlock_tcp_connections disables repair mode for sockets and drops
netfilters. netfilters are not used in case of network namespaces.

v2: don't execute network-unlock scripts, if network namespace are not
    dumped.

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