1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#include <fcntl.h>
#include <unistd.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <linux/limits.h>
#include "zdtmtst.h"
const char *test_doc = "Check unbindable flag does not break mount restore";
const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>";
char *dirname;
TEST_OPTION(dirname, string, "directory name", 1);
int main(int argc, char **argv)
{
char unbindable[PATH_MAX], bind_of_unbindable[PATH_MAX];
char auxiliary[PATH_MAX];
test_init(argc, argv);
mkdir(dirname, 0700);
snprintf(unbindable, sizeof(unbindable), "%s/unbindable", dirname);
if (mkdir(unbindable, 0700)) {
pr_perror("Unable to mkdir %s", unbindable);
return 1;
}
if (mount("unbindable", unbindable, "tmpfs", 0, NULL)) {
pr_perror("Unable to mount tmpfs to %s", unbindable);
return 1;
}
snprintf(auxiliary, sizeof(auxiliary), "%s/unbindable/auxiliary", dirname);
if (mkdir(auxiliary, 0700)) {
pr_perror("Unable to mkdir %s", auxiliary);
return 1;
}
snprintf(bind_of_unbindable, sizeof(bind_of_unbindable), "%s/bind_of_unbindable", dirname);
if (mkdir(bind_of_unbindable, 0700)) {
pr_perror("Unable to mkdir %s", bind_of_unbindable);
return 1;
}
if (mount(auxiliary, bind_of_unbindable, NULL, MS_BIND, NULL)) {
pr_perror("Unable to mount %s to %s", unbindable, bind_of_unbindable);
return 1;
}
if (mount(NULL, unbindable, NULL, MS_UNBINDABLE, NULL)) {
pr_perror("Unable to set %s unbindable", unbindable);
return 1;
}
test_daemon();
test_waitsig();
if (umount(bind_of_unbindable)) {
pr_perror("Unable to umount %s", bind_of_unbindable);
return 1;
}
if (umount(unbindable)) {
pr_perror("Unable to umount %s", unbindable);
return 1;
}
pass();
return 0;
}
|