Commit a08f2030 authored by Kinsbursky Stanislav's avatar Kinsbursky Stanislav Committed by Pavel Emelyanov

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: 's avatarStanislav Kinsbursky <skinsbursky@openvz.org>
Acked-by: 's avatarAndrew Vagin <avagin@parallels.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent f33df79e
......@@ -66,6 +66,7 @@ static/pty00
static/pty01
static/pty04
static/tty02
static/child_opened_proc
"
# Duplicate list with ns/ prefix
TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#ns/#')
......
......@@ -74,6 +74,7 @@ TST_NOFILE = \
socket-ext \
unhashed_proc \
cow00 \
child_opened_proc \
posix_timers \
# jobctl00 \
......
#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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment