From e9d0499cd1b2f739d56708cb6c1c0ab03691bfd8 Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Wed, 17 Sep 2014 15:32:18 -0500 Subject: [PATCH] test: add a test for remap_dead_pid Signed-off-by: Tycho Andersen Signed-off-by: Pavel Emelyanov --- test/zdtm.sh | 1 + test/zdtm/.gitignore | 1 + test/zdtm/live/static/Makefile | 1 + test/zdtm/live/static/remap_dead_pid.c | 74 ++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 test/zdtm/live/static/remap_dead_pid.c diff --git a/test/zdtm.sh b/test/zdtm.sh index b9a77081e..3c420e6de 100755 --- a/test/zdtm.sh +++ b/test/zdtm.sh @@ -179,6 +179,7 @@ static/cgroup00 static/cgroup01 static/cgroup02 ns/static/clean_mntns +static/remap_dead_pid " TEST_CR_KERNEL=" diff --git a/test/zdtm/.gitignore b/test/zdtm/.gitignore index a8f60b96c..fef561dab 100644 --- a/test/zdtm/.gitignore +++ b/test/zdtm/.gitignore @@ -90,6 +90,7 @@ /live/static/pty02 /live/static/pty03 /live/static/pty04 +/live/static/remap_dead_pid /live/static/rlimits00 /live/static/rmdir_open /live/static/rtc diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile index e07920106..e44bf6a27 100644 --- a/test/zdtm/live/static/Makefile +++ b/test/zdtm/live/static/Makefile @@ -113,6 +113,7 @@ TST_NOFILE = \ clean_mntns \ dumpable01 \ dumpable02 \ + remap_dead_pid \ # jobctl00 \ TST_FILE = \ diff --git a/test/zdtm/live/static/remap_dead_pid.c b/test/zdtm/live/static/remap_dead_pid.c new file mode 100644 index 000000000..4e3953a2e --- /dev/null +++ b/test/zdtm/live/static/remap_dead_pid.c @@ -0,0 +1,74 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include + +#include "zdtmtst.h" + +#ifndef CLONE_NEWNS +#define CLONE_NEWNS 0x00020000 +#endif + +const char *test_doc = "Check that dead pid's /proc entries are remapped correctly"; +const char *test_author = "Tycho Andersen "; + +int main(int argc, char **argv) +{ + pid_t pid; + + test_init(argc, argv); + + pid = fork(); + if (pid < 0) { + fail("fork() failed"); + return -1; + } + + if (pid == 0) { + test_msg("child is %d\n", pid); + /* Child process just sleeps until it is killed. All we need + * here is a process to open the mountinfo of. */ + while(1) + sleep(10); + } else { + int fd, ret; + char path[PATH_MAX]; + pid_t result; + + sprintf(path, "/proc/%d/mountinfo", pid); + + fd = open(path, O_RDONLY); + + /* no matter what, we should kill the child */ + kill(pid, SIGINT); + result = waitpid(pid, NULL, 0); + if (result < 0) { + fail("failed waitpid()"); + return -1; + } + + if (fd < 0) { + fail("failed opening %s", path); + return -1; + } + + test_daemon(); + test_waitsig(); + + ret = fcntl(fd, F_GETFD); + close(fd); + + if (ret) { + fail("bad fd after restore"); + return -1; + } + } + + pass(); + return 0; +}