mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 09:58:09 +00:00
zdtm: Check a private mount in a shared mount
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
parent
fbdc00391d
commit
ab8fdf82b3
@ -225,6 +225,7 @@ TST_DIR = \
|
||||
mntns_shared_bind02 \
|
||||
mntns_root_bind \
|
||||
mntns_root_bind02 \
|
||||
mntns_shared_vs_private \
|
||||
mnt_ext_auto \
|
||||
mnt_ext_master \
|
||||
mntns_deleted \
|
||||
|
118
test/zdtm/static/mntns_shared_vs_private.c
Normal file
118
test/zdtm/static/mntns_shared_vs_private.c
Normal file
@ -0,0 +1,118 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sched.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "zdtmtst.h"
|
||||
|
||||
#ifndef CLONE_NEWNS
|
||||
#define CLONE_NEWNS 0x00020000
|
||||
#endif
|
||||
|
||||
const char *test_doc = "Check a private mount in a shared mount";
|
||||
const char *test_author = "Andrew Vagin <avagin@gmail.com>";
|
||||
|
||||
char *dirname;
|
||||
TEST_OPTION(dirname, string, "directory name", 1);
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
pid_t pid;
|
||||
int status, i;
|
||||
task_waiter_t t;
|
||||
|
||||
test_init(argc, argv);
|
||||
|
||||
task_waiter_init(&t);
|
||||
|
||||
snprintf(path, sizeof(path), "%s/fs", dirname);
|
||||
if (mkdir(dirname, 0700)) {
|
||||
pr_perror("mkdir");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mount(NULL, "/", NULL, MS_SHARED, NULL)) {
|
||||
pr_perror("mount");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mount("zdtm_fs", dirname, "tmpfs", 0, NULL)) {
|
||||
pr_perror("mount");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mount(NULL, dirname, NULL, MS_PRIVATE, NULL)) {
|
||||
pr_perror("mount");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mkdir(path, 0700)) {
|
||||
pr_perror("mkdir");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (mount("zdtm_fs", path, "tmpfs", 0, NULL)) {
|
||||
pr_perror("mount");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
pr_perror("fork");
|
||||
return 1;
|
||||
}
|
||||
if (pid == 0) {
|
||||
unshare(CLONE_NEWNS);
|
||||
|
||||
task_waiter_complete(&t, 1);
|
||||
task_waiter_wait4(&t, 2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
task_waiter_wait4(&t, 1);
|
||||
|
||||
test_daemon();
|
||||
test_waitsig();
|
||||
|
||||
if (umount(path)) {
|
||||
pr_perror("Unable to umount %s\n", path);
|
||||
return 1;
|
||||
}
|
||||
if (umount(dirname)) {
|
||||
pr_perror("Unable to umount %s\n", dirname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
task_waiter_complete(&t, 2);
|
||||
|
||||
if (waitpid(-1, &status, 0) < 0) {
|
||||
pr_perror("waitpid %d", pid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
pr_perror("%d/%d/%d/%d", WIFEXITED(status), WEXITSTATUS(status), WIFSIGNALED(status), WTERMSIG(status));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
pass();
|
||||
|
||||
return 0;
|
||||
}
|
1
test/zdtm/static/mntns_shared_vs_private.desc
Normal file
1
test/zdtm/static/mntns_shared_vs_private.desc
Normal file
@ -0,0 +1 @@
|
||||
{'flavor': 'ns uns', 'flags': 'suid', 'feature': 'mnt_id'}
|
Loading…
x
Reference in New Issue
Block a user