Commit e9d0499c authored by Tycho Andersen's avatar Tycho Andersen Committed by Pavel Emelyanov

test: add a test for remap_dead_pid

Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent f020bef7
......@@ -179,6 +179,7 @@ static/cgroup00
static/cgroup01
static/cgroup02
ns/static/clean_mntns
static/remap_dead_pid
"
TEST_CR_KERNEL="
......
......@@ -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
......
......@@ -113,6 +113,7 @@ TST_NOFILE = \
clean_mntns \
dumpable01 \
dumpable02 \
remap_dead_pid \
# jobctl00 \
TST_FILE = \
......
#define _GNU_SOURCE
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/wait.h>
#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 <tycho.andersen@canonical.com>";
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;
}
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