Commit fee9021f authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

zdtm: test inotifies in a sub mount namespace

Signed-off-by: 's avatarAndrew Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent addbc255
...@@ -226,6 +226,7 @@ generate_test_list() ...@@ -226,6 +226,7 @@ generate_test_list()
ns/static/mntns_shared_bind02 ns/static/mntns_shared_bind02
ns/static/mntns_root_bind ns/static/mntns_root_bind
ns/static/mntns_deleted ns/static/mntns_deleted
ns/static/inotify01
" "
TEST_AIO=" TEST_AIO="
...@@ -358,6 +359,7 @@ cow01 ...@@ -358,6 +359,7 @@ cow01
apparmor apparmor
seccomp_strict seccomp_strict
different_creds different_creds
inotify01
" "
TEST_EXPECTED_FAILURE=" TEST_EXPECTED_FAILURE="
......
...@@ -189,6 +189,7 @@ TST_DIR = \ ...@@ -189,6 +189,7 @@ TST_DIR = \
mount_paths \ mount_paths \
bind-mount \ bind-mount \
inotify00 \ inotify00 \
inotify01 \
cgroup00 \ cgroup00 \
rmdir_open \ rmdir_open \
cgroup01 \ cgroup01 \
...@@ -338,6 +339,7 @@ mntns_link_remap: override CFLAGS += -DZDTM_LINK_REMAP ...@@ -338,6 +339,7 @@ mntns_link_remap: override CFLAGS += -DZDTM_LINK_REMAP
mntns_shared_bind02: override CFLAGS += -DSHARED_BIND02 mntns_shared_bind02: override CFLAGS += -DSHARED_BIND02
maps02: get_smaps_bits.o maps02: get_smaps_bits.o
mlock_setuid: get_smaps_bits.o mlock_setuid: get_smaps_bits.o
inotify01: override CFLAGS += -DINOTIFY01
$(LIB): force $(LIB): force
$(Q) $(MAKE) -C $(LIBDIR) $(Q) $(MAKE) -C $(LIBDIR)
......
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <dirent.h> #include <dirent.h>
#include <signal.h>
#include <sched.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include "zdtmtst.h" #include "zdtmtst.h"
...@@ -114,14 +118,61 @@ int main (int argc, char *argv[]) ...@@ -114,14 +118,61 @@ int main (int argc, char *argv[])
test_init(argc, argv); test_init(argc, argv);
fd = inotify_init1(IN_NONBLOCK); if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
if (fd < 0) { err("Can't create directory %s", dirname);
err("inotify_init failed");
exit(1); exit(1);
} }
if (mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { #ifdef INOTIFY01
err("Can't create directory %s", dirname); {
pid_t pid;
task_waiter_t t;
task_waiter_init(&t);
static char buf[PATH_MAX];
if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL)) {
err("Unable to remount /");
return 1;
}
pid = fork();
if (pid < 0) {
err("Can't fork a test process");
exit(1);
}
if (pid == 0) {
int fd;
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
if (unshare(CLONE_NEWNS)) {
err("Unable to unshare mount namespace");
exit(1);
}
if (mount("zdtm", dirname, "tmpfs", 0, NULL)) {
err("Unable to mount tmpfs");
exit(1);
}
fd = open(dirname, O_RDONLY);
if (fd < 0) {
err("Unable to open %s", dirname);
exit(1);
}
dup2(fd, 100);
task_waiter_complete_current(&t);
while (1)
sleep(1000);
exit(1);
}
task_waiter_wait4(&t, pid);
snprintf(buf, sizeof(buf), "/proc/%d/fd/100", pid);
dirname = buf;
}
#endif
fd = inotify_init1(IN_NONBLOCK);
if (fd < 0) {
err("inotify_init failed");
exit(1); exit(1);
} }
...@@ -149,6 +200,7 @@ int main (int argc, char *argv[]) ...@@ -149,6 +200,7 @@ int main (int argc, char *argv[])
* hardlink are opened. * hardlink are opened.
*/ */
#ifndef INOTIFY01
if (unlink(test_file_path)) { if (unlink(test_file_path)) {
err("can't unlink %s\n", test_file_path); err("can't unlink %s\n", test_file_path);
exit(1); exit(1);
...@@ -163,6 +215,7 @@ int main (int argc, char *argv[]) ...@@ -163,6 +215,7 @@ int main (int argc, char *argv[])
emask, emask_bits); emask, emask_bits);
exit(1); exit(1);
} }
#endif
test_daemon(); test_daemon();
test_waitsig(); test_waitsig();
...@@ -179,6 +232,7 @@ int main (int argc, char *argv[]) ...@@ -179,6 +232,7 @@ int main (int argc, char *argv[])
return 1; return 1;
} }
#ifndef INOTIFY01
real_fd = open(test_file_path, O_CREAT | O_TRUNC | O_RDWR, 0644); real_fd = open(test_file_path, O_CREAT | O_TRUNC | O_RDWR, 0644);
if (real_fd < 0) { if (real_fd < 0) {
err("Can't create %s", test_file_path); err("Can't create %s", test_file_path);
...@@ -195,6 +249,7 @@ int main (int argc, char *argv[]) ...@@ -195,6 +249,7 @@ int main (int argc, char *argv[])
emask, emask_bits); emask, emask_bits);
return 1; return 1;
} }
#endif
pass(); pass();
......
inotify00.c
\ No newline at end of file
{'flags': 'suid', 'flavor': 'ns uns'}
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