Commit ae4796d0 authored by Konstantin Khlebnikov's avatar Konstantin Khlebnikov Committed by Pavel Emelyanov

zdtm: new testcase for unhashed proc entries

Testcase: fork child, chdir into /proc/$pid and kill child.

test for http://bugzilla.openvz.org/show_bug.cgi?id=2315Signed-off-by: 's avatarKonstantin Khlebnikov <khlebnikov@openvz.org>
Acked-by: 's avatarAndrey Wagin <avagin@gmail.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent e628b63b
......@@ -62,6 +62,7 @@ TST_NOFILE = \
netns \
session01 \
socket-ext \
unhashed_proc \
# jobctl00 \
TST_FILE = \
......
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <string.h>
#include <linux/limits.h>
#include "zdtmtst.h"
const char *test_doc = "Chdir into unhashed proc entry";
const char *test_author = "Konstantin Khlebnikov <khlebnikov@openvz.org>";
int main(int argc, char ** argv)
{
int pid, len;
char cwd1[PATH_MAX], cwd2[PATH_MAX];
test_init(argc, argv);
pid = fork();
if (pid < 0) {
err("Fork failed %m\n");
exit(1);
} else if (!pid) {
pause();
return 0;
}
sprintf(cwd1, "/proc/%d", pid);
if (chdir(cwd1) < 0) {
kill(pid, SIGKILL);
err("Chdir failed %m\n");
exit(1);
}
kill(pid, SIGKILL);
waitpid(pid, NULL, 0);
if (getcwd(cwd1, sizeof(cwd1))) {
err("successfull getcwd: %s\n", cwd1);
exit(1);
} else if (errno != ENOENT) {
err("wrong errno: %m\n");
exit(1);
}
len = readlink("/proc/self/cwd", cwd1, sizeof(cwd1));
if (len < 0) {
err("can't read cwd symlink %m\n");
exit(1);
}
cwd1[len] = 0;
test_daemon();
test_waitsig();
if (getcwd(cwd2, sizeof(cwd2))) {
fail("successfull getcwd: %s\n", cwd2);
exit(1);
} else if (errno != ENOENT) {
fail("wrong errno: %m\n");
exit(1);
}
len = readlink("/proc/self/cwd", cwd2, sizeof(cwd2)-1);
if (len < 0) {
fail("can't read cwd symlink %m\n");
exit(1);
}
cwd2[len] = 0;
if (strcmp(cwd1, cwd2))
test_msg("cwd differs: %s != %s\n", cwd1, cwd2);
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