Quick bug fix for missing fd for move_in_cgroup

There is an issue where if the proccess to be killed spawns a child proccess and
moves it in a child cgroup of the one the parent process is in, the cgroup fd
was being closed in the parent process before it forked the child. Then when
move_in_cgroup() is called for the child process, the file descriptor has
already been closed causing a failure for the second call to move_in_cgroup().
Moved the fd close after the fork call.

Change-Id: I6ae88b95c5410a7f56108e28eb3133f113e868d0
Signed-off-by: Garrison Bellack <gbellack@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Minor change in protobuf/cgroup.proto numbering

Change-Id: Idaf8689188041c848126beb9c401bd90d0e2be69
Signed-off-by: Garrison Bellack <gbellack@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Cgroup property restoration infrastructure

Restores 2 cgroup properties after the criu restoration of tasks.
Currently the cgroup files to be restored are static but
are easily extendable. To change the properties to be restored,
edit this list at the top of cgroup.c. If a cgroup exists during
restoration, its properties will not be overwritten.
Work based off Tycho Anderson tycho.andersen@canonical.com

Change-Id: Ida32b9773eeac1d4d6e82ad644524ed099d5f9b1
Signed-off-by: Garrison Bellack <gbellack@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Fill out cgroup properties restoration list

Building on top of the cgroup properties infrastructure patch, this patch will
add all the cgroups properties to the static list of properties we want to restore.

Change-Id: I992c260089dcc2ba169a8ac5b19d73f29c678e7d
Signed-off-by: Garrison Bellack <gbellack@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: don't execute mntns_* tests, if the kernel doesn't show mnt_id

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: Replace `ps -p` with `kill -0`

The -p argument to `ps` is not supported by Busybox v1.19.4. Sending
signal 0 with the `kill` command is an alternative way to check
whether a process is still running.

http://www.linuxjournal.com/content/monitoring-processes-kill-0

Signed-off-by: Christopher Covington <cov@codeaurora.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: Make use of $test consistently

The $test variable was being used without being locally defined in
the start_test function. Define it locally for uniformity with other
functions and use it where convenient. Also make the definition in
case_error local for uniformity with other functions.

Signed-off-by: Christopher Covington <cov@codeaurora.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
mnt: Don't delay external mount points

It looks like criu constantly postpones external bind mounts. I'm trying to resolve
when we manage to break this (when I did ext-mount-map they for some reason didn't).
Meanwhile, this patch fixes it back.

Reported-by: Saied Kazemi <saied@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
opts: add --manage-cgroups option

criu managed cgroups is now an opt-in thing, so by default criu does not manage
(i.e. dump or restore) cgroups. This allows users to use the previous behavior.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
cg: Don't close cgyard early when inherit cgroups

Fix for closed cgyard descriptor for changed cgroup was 9752c11d.
One more place left.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: Sanitize cgroup00 test

Prepare it for multiple tasks by moving cg creation and
checking code into helpers.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: Make cgroup00 test check several tasks and sub-cgroup

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
restore: use /proc/self/mountinfo for collecting mounts fo the root task (v3)

If the root task is forked in a new pidns, it can't use its pid for
accessing /proc, because this proc belongs to the source pidns.

v2: don't copy a static string.
v3: take a bright part of Tycho's patch

Reported-by: Tycho Andersen <tycho.andersen@canonical.com>
Cc: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
stats: Properly initialize dump stats

They all should be zeroed.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
flock: Don't hide image read error on flocks restore

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
img: Add ability to check whether optional image collection happened

A bit later we'd need to check whether cinfo collector
opened an image or not due to file absense.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
flock: Merge all file lock entries into single image file

They are now in per-pid images, but every entry contains a
pid to which it "belongs". This belonging is fake -- it's
just a pid of a task who placed the lock, while locks really
belong to files. We even have a bug when task that locked
a file exited and "delegated" the lock to its child.

This images merge reduces the amount of image files criu
generates and may simplify the fix of mentioned above issue.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm.sh: add a test directory name in a path to images

Otherwise static/socket-tcp and streaming/socket-tcp have the same path
to images and they can affect each other.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
pstree: Introduce task_alive() helper

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
pstree: Use task_alive() instead of switch()-es

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