2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-29 13:28:27 +00:00

test: add processes tree restoring test

This test makes sure, that processes tree is restored before opened files.
This is guaranteed by holding child's "/proc/<pid>/stat" file opened by parent.

It was inspired by OpenVZ bug:
#2404

IOW, OpenVZ can't restore container with such test inside.

v2:
1) Test renamed + carefull cleanup + minor updates.

Signed-off-by: Stanislav Kinsbursky <skinsbursky@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Kinsbursky Stanislav 2012-11-01 14:45:51 +04:00 committed by Pavel Emelyanov
parent f33df79e1e
commit a08f2030a1
3 changed files with 65 additions and 0 deletions

View File

@ -66,6 +66,7 @@ static/pty00
static/pty01 static/pty01
static/pty04 static/pty04
static/tty02 static/tty02
static/child_opened_proc
" "
# Duplicate list with ns/ prefix # Duplicate list with ns/ prefix
TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#ns/#') TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#ns/#')

View File

@ -74,6 +74,7 @@ TST_NOFILE = \
socket-ext \ socket-ext \
unhashed_proc \ unhashed_proc \
cow00 \ cow00 \
child_opened_proc \
posix_timers \ posix_timers \
# jobctl00 \ # jobctl00 \

View File

@ -0,0 +1,63 @@
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include "zdtmtst.h"
const char *test_doc = "Check that tree prior to files opening";
const char *test_author = "Stanislav Kinsbursky <skinsbursky@paralles.com";
int main(int argc, char ** argv)
{
int pid, err = 0;
int proc_fd;
char name[64];
test_init(argc, argv);
pid = test_fork();
if (pid < 0) {
err("Can't fork");
exit(1);
}
if (!pid) {
test_waitsig();
return 0;
}
sprintf(name, "/proc/%d/stat", pid);
proc_fd = open(name, O_RDONLY);
if (proc_fd == -1) {
err("can't open %s: %m\n", name);
err++;
goto out;
}
test_daemon();
test_waitsig();
if (close(proc_fd) == -1) {
err("Failed to close %s\n", name);
err++;
}
out:
if (kill(pid, SIGTERM) == -1) {
err("Failed to terminate child\n");
err++;
} else {
if (waitpid(pid, NULL, 0) != pid) {
err("Failed to collect killed child\n");
err++;
}
}
if (!err)
pass();
return err;
}