mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-03 07:45:17 +00:00
zdtm: don't destruct an external mount-namespace
Before doing something with mounts they should be marked as private, otherwise our actions can affects someone else. Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
7aaef1ee4f
commit
55fe093908
@@ -1,3 +1,4 @@
|
|||||||
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -18,11 +19,8 @@ static int test_fn(int argc, char **argv)
|
|||||||
FILE *f;
|
FILE *f;
|
||||||
int fd, tmpfs_fd;
|
int fd, tmpfs_fd;
|
||||||
unsigned fs_cnt, fs_cnt_last = 0;
|
unsigned fs_cnt, fs_cnt_last = 0;
|
||||||
|
bool private = false;
|
||||||
|
|
||||||
if (mount("none", "/", "none", MS_REC|MS_PRIVATE, NULL)) {
|
|
||||||
err("Can't remount root with MS_PRIVATE");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
again:
|
again:
|
||||||
fs_cnt = 0;
|
fs_cnt = 0;
|
||||||
f = fopen("/proc/self/mountinfo", "r");
|
f = fopen("/proc/self/mountinfo", "r");
|
||||||
@@ -41,18 +39,31 @@ again:
|
|||||||
end = strchr(mp, ' ');
|
end = strchr(mp, ' ');
|
||||||
*end = '\0';
|
*end = '\0';
|
||||||
|
|
||||||
if (!strcmp(mp, "/"))
|
if (private) {
|
||||||
continue;
|
if (!strcmp(mp, "/"))
|
||||||
if (!strcmp(mp, "/proc"))
|
continue;
|
||||||
continue;
|
if (!strcmp(mp, "/proc"))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (umount(mp))
|
if (umount(mp))
|
||||||
test_msg("umount(`%s') failed: %m\n", mp);
|
test_msg("umount(`%s') failed: %m\n", mp);
|
||||||
|
} else {
|
||||||
|
/* mount --make-rprivate / */
|
||||||
|
if (mount("none", mp, "none", MS_REC|MS_PRIVATE, NULL)) {
|
||||||
|
err("Can't remount %s with MS_PRIVATE", mp);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
fs_cnt++;
|
fs_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
if (!private) {
|
||||||
|
private = true;
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
|
||||||
if (fs_cnt == 0)
|
if (fs_cnt == 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user