unseize: Don't print error when unseizing stopped task into stopped state

Just a small mistake in prev patch.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
lib: don't copy more than the buffer size

CID 1141012 (#1 of 1): Copy into fixed size buffer (STRING_OVERFLOW)
2. fixed_size_dest: You might overrun the 108 byte fixed-size string
"addr.sun_path" by copying "service_address" without checking the
length.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
ptrace: check, that PTRACE_LISTEN isn't defined yet

In file included from arch/x86/crtools.c:11:0:
include/ptrace.h:16:0: error: "PTRACE_LISTEN" redefined [-Werror]
 #define PTRACE_LISTEN  0x4208
 ^
In file included from include/ptrace.h:5:0,
                 from arch/x86/crtools.c:11:
/usr/include/sys/ptrace.h:150:0: note: this is the location of the previous definition
 #define PTRACE_LISTEN PTRACE_LISTEN
 ^
cc1: all warnings being treated as errors
make[1]: *** [arch/x86/crtools.o] Error 1

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: increase the amount of allowable inaccuracy

The timeout can be exceeded during dumping and restoring.
When we are testing snapshots, the test is dumped three times.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
unix: fix double free on error paths

CID 1141011 (#1 of 1): Double free (USE_AFTER_FREE)
24. double_free: Calling "free(void *)" frees pointer "ue" which has
already been freed.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
image: don't leak a file descriptor

CID 1141015 (#1 of 1): Resource leak (RESOURCE_LEAK)
8. leaked_handle: Handle variable fd going out of scope leaks the handle.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
service: don't leak a zero file descriptor

CID 1141017 (#1-2 of 2): Resource leak (RESOURCE_LEAK)
14. leaked_handle: Handle variable fd going out of scope leaks the handle.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
unix: fix calculation of pointers

CID 1141016 (#1 of 1): Extra sizeof expression (SIZEOF_MISMATCH)
suspicious_pointer_arithmetic: Adding "40UL /* sizeof (FilePermsEntry)
*/" to pointer "(FownEntry *)perms" of type "FownEntry *" is suspicious
because adding an integral value to this pointer automatically scales
that value by the size, 48 bytes, of the pointed-to type, "FownEntry".
Most likely, "sizeof (FilePermsEntry)" is extraneous and should be
replaced with 1.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: Split reading images and populating the ns

We will need images at hands while we do pivot_root (see further patches),
so prepare the images reading routine.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: Make images reader return the list of mounts

To carry them with us in a local variable (next patches), not
the global mntinfo one.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: Read mount images eary

We'll have to pre-mount some, so move the read_mnt_ns_img
before pivot_root call.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: Fix the mi we print info about

The t and m match there, but strictly speaking we're working on the m.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: Dump external bind-mounts with plugins

External bind mounts are those with source sitting outside of the
current FS view. Such are detected in validate_mounts(), so we
just go ahead and call plugins.

The plugin is provided with the mountpoint to decide whether it's
his or not (what else does the guy need?) and an ID with this it
can identify the mountpoint in /proc. The same ID will be used at
restore time to find the needed restore info.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: Restore external bind-mounts with plugins

All the entries with with_plugin set will be mounted by plugin.
The interesting case is when we do the pivot-root restore. In this
case we call restore callback very early (before we unmount the old
tree) and ask it to create the mountpoint at temporary location.
Later we move the mount to proper place.

The old_root argument of the callback is where it can find files
in the original mount namespace.

The is_file is return-argument. Sine files and directories cannot be
bind-mounted to each-other, the callback should create the mountpoint
itself and report whether it created file or directory.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
test: Test and example of external bind mounts plugin

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
plugins: Don't strdup libdir arg

It's not freed anywhere. Makes code look simpler.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
plugins: Don't return from inside a macro

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
crtools: fixed format strings

Use the format specifier %zu instead of %lu to print a size_t integer.

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mount: Add comment to is_root_xxx checks

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