zdtm/maps007: don't use signed values in calculations

maps007 segfaults on i386, because "size" is calculated bigger than allowed.

This occurs when the result of lrand48() * PAGE_SIZE is negative.
In this case the % operation returns a negative value too, what is unexpected.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm/pty02: never close master before reading slave

We may close the master before reading the slave if the child runs first
when the parent wakes it up using task_waiter_complete. In this case the
subsequent read from the slave will return 0 resulting in a false
positive test failure:

13:23:42.194: 30914: ERR: pty02.c:89: read(slave) failed (errno = 11 (Resource temporarily unavailable))

Fix this by waking the child, which closes the master, only after the
read has been completed.

Also note errno = EAGAIN in the failure report above, which looks really
confusing. Let's print the actual number of bytes read/written along
with the errno while reporting a read/write failure to make the error
reporting clearer in this test.

Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Cyrill Gorcunov <gorcunov@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
Acked-by: Cyrill Gorcunov <gorcunov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: don't forget to remove ip.dump and ip.rst when performing cleanup

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tcp: don't split packets for restoring a send queue

The kernel can do it better. The problem exists only for recv queues.

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

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
arch:arm: add atomic_cmpxchg

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
arch:aarch64: add atomic_cmpxchg

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
criu: check: don't leak the child if PTRACE_ATTACH fails

PS: never ever use PTRACE_KILL.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
criu/testing: caps00: don't hang if PR_CAPBSET_DROP fails

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Add inherit fd support

There are cases where a process's file descriptor cannot be restored
from the checkpoint images.  For example, a pipe file descriptor with
one end in the checkpointed process and the other end in a separate
process (that was not part of the checkpointed process tree) cannot be
restored because after checkpoint the pipe will be broken.

There are also cases where the user wants to use a new file during
restore instead of the original file at checkpoint time.  For example,
the user wants to change the log file of a process from /path/to/oldlog
to /path/to/newlog.

In these cases, criu's caller should set up a new file descriptor to be
inherited by the restored process and specify the file descriptor with the
--inherit-fd command line option.  The argument of --inherit-fd has the
format fd[%d]:%s, where %d tells criu which of its own file descriptors
to use for restoring the file identified by %s.

As a debugging aid, if the argument has the format debug[%d]:%s, it tells
criu to write out the string after colon to the file descriptor %d.  This
can be used, for example, as an easy way to leave a "restore marker"
in the output stream of the process.

It's important to note that inherit fd support breaks applications
that depend on the state of the file descriptor being inherited.  So,
consider inherit fd only for specific use cases that you know for sure
won't break the application.

For examples please visit http://criu.org/Category:HOWTO.

v2: Added a check in send_fd_to_self() to avoid closing an inherit fd.
    Also, as an extra measure of caution, added checks in the inherit fd
    look up functions to make sure that the inherit fd hasn't been reused.
    The patch also includes minor cosmetic changes.

Signed-off-by: Saied Kazemi <saied@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm: add ip.dump and ip.rst to gitignore

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
zdtm/cwd00: avoid resolving an abs path

We may not have permissions for this.

Reported-by: Ruslan Kuprieiev <kupruser@gmail.com>
Cc: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
tests: Pipe.c Test Program

Hi Saied,

This patch adds your test in the criu test system.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
libcriu: print error if exec failed

Reported-by: Paschalis Mpeis <paschalis.mpeis@ed.ac.uk>
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>