static void test(void) { int status; /* unshares the mount ns */ if (unshare(CLONE_NEWNS) == -1) tst_brkm(TBROK | TERRNO, cleanup, "unshare failed"); /* makes sure parent mounts/umounts have no effect on a real system */ SAFE_MOUNT(cleanup, "none", "/", "none", MS_REC|MS_PRIVATE, NULL); /* bind mounts DIRA to itself */ SAFE_MOUNT(cleanup, DIRA, DIRA, "none", MS_BIND, NULL); /* makes mount DIRA shared */ SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_SHARED, NULL); if (do_clone_tests(CLONE_NEWNS, child_func, NULL, NULL, NULL) == -1) tst_brkm(TBROK | TERRNO, cleanup, "clone failed"); /* waits for child to make a slave mount */ TST_CHECKPOINT_PARENT_WAIT(cleanup, &checkpoint1); /* bind mounts DIRB to DIRA making contents of DIRB visible * in DIRA */ SAFE_MOUNT(cleanup, DIRB, DIRA, "none", MS_BIND, NULL); TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint2); TST_CHECKPOINT_PARENT_WAIT(cleanup, &checkpoint1); SAFE_UMOUNT(cleanup, DIRA); TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint2); TST_CHECKPOINT_PARENT_WAIT(cleanup, &checkpoint1); /* checks that slave mount doesn't propagate to shared mount */ if ((access(DIRA"/A", F_OK) == 0) && (access(DIRA"/B", F_OK) == -1)) tst_resm(TPASS, "propagation from slave mount passed"); else tst_resm(TFAIL, "propagation form slave mount failed"); TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint2); SAFE_WAIT(cleanup, &status); if (WIFEXITED(status)) { if (WEXITSTATUS(status) == 0) tst_resm(TPASS, "propagation to slave mount passed"); else tst_resm(TFAIL, "propagation to slave mount failed"); } if (WIFSIGNALED(status)) { tst_resm(TBROK, "child was killed with signal %s", tst_strsig(WTERMSIG(status))); return; } SAFE_UMOUNT(cleanup, DIRA); }
static void test(void) { int status; /* unshares the mount ns */ if (unshare(CLONE_NEWNS) == -1) tst_brkm(TBROK | TERRNO, cleanup, "unshare failed"); /* makes sure parent mounts/umounts have no effect on a real system */ SAFE_MOUNT(cleanup, "none", "/", "none", MS_REC|MS_PRIVATE, NULL); /* bind mounts DIRA to itself */ SAFE_MOUNT(cleanup, DIRA, DIRA, "none", MS_BIND, NULL); /* makes mount DIRA shared */ SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_SHARED, NULL); if (do_clone_tests(CLONE_NEWNS, child_func, NULL, NULL, NULL) == -1) tst_brkm(TBROK | TERRNO, cleanup, "clone failed"); /* bind mounts DIRB to DIRA making contents of DIRB visible * in DIRA */ SAFE_MOUNT(cleanup, DIRB, DIRA, "none", MS_BIND, NULL); TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 0); SAFE_UMOUNT(cleanup, DIRA); TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 0); if (access(DIRA"/B", F_OK) == 0) tst_resm(TPASS, "shared mount in child passed"); else tst_resm(TFAIL, "shared mount in child failed"); TST_SAFE_CHECKPOINT_WAKE(cleanup, 0); SAFE_WAIT(cleanup, &status); if (WIFEXITED(status)) { if ((WEXITSTATUS(status) == 0)) tst_resm(TPASS, "shared mount in parent passed"); else tst_resm(TFAIL, "shared mount in parent failed"); } if (WIFSIGNALED(status)) { tst_resm(TBROK, "child was killed with signal %s", tst_strsig(WTERMSIG(status))); return; } SAFE_UMOUNT(cleanup, DIRA); }
int main(int ac, char **av) { int lc; int tc; tst_parse_opts(ac, av, NULL, NULL); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL); mount_flag = 1; for (tc = 0; tc < TST_TOTAL; tc++) test_umount2(tc); if (mount_flag) { SAFE_UMOUNT(cleanup, MNTPOINT); mount_flag = 0; } } cleanup(); tst_exit(); }
static void cleanup(void) { if (ovl_mounted) SAFE_UMOUNT(OVL_MNT); if (orig_bdi_limit) SAFE_FILE_PRINTF(sys_bdi_ra_path, "%d", orig_bdi_limit); }
static void test(void) { /* unshares the mount ns */ if (unshare(CLONE_NEWNS) == -1) tst_brkm(TBROK | TERRNO, cleanup, "unshare failed"); /* makes sure mounts/umounts have no effect on a real system */ SAFE_MOUNT(cleanup, "none", "/", "none", MS_REC|MS_PRIVATE, NULL); /* bind mounts DIRA to itself */ SAFE_MOUNT(cleanup, DIRA, DIRA, "none", MS_BIND, NULL); /* makes mount DIRA unbindable */ SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_UNBINDABLE, NULL); /* tries to bind mount unbindable DIRA to DIRB which should fail */ if (mount(DIRA, DIRB, "none", MS_BIND, NULL) == -1) { tst_resm(TPASS, "unbindable mount passed"); } else { SAFE_UMOUNT(cleanup, DIRB); tst_resm(TFAIL, "unbindable mount faled"); } SAFE_UMOUNT(cleanup, DIRA); }
static void setup(void) { char path[PATH_MAX]; struct stat file_stat; tst_sig(FORK, DEF_HANDLER, cleanup); tst_require_root(); tst_tmpdir(); fs_type = tst_dev_fs_type(); device = tst_acquire_device(cleanup); if (!device) tst_brkm(TCONF, cleanup, "Failed to obtain block device"); tst_mkfs(cleanup, device, fs_type, NULL, NULL); SAFE_MKDIR(cleanup, mntpoint, DIR_MODE); if (getcwd(path_name, sizeof(path_name)) == NULL) tst_brkm(TBROK, cleanup, "getcwd failed"); if (chmod(path_name, DIR_MODE) != 0) tst_brkm(TBROK, cleanup, "chmod(%s, %#o) failed", path_name, DIR_MODE); strncpy(path, path_name, PATH_MAX); snprintf(path_name, PATH_MAX, "%s/%s/", path, mntpoint); SAFE_MOUNT(cleanup, device, mntpoint, fs_type, 0, NULL); TST_RESOURCE_COPY(cleanup, "mount03_setuid_test", path_name); snprintf(file, PATH_MAX, "%smount03_setuid_test", path_name); SAFE_STAT(cleanup, file, &file_stat); if (file_stat.st_mode != SUID_MODE && chmod(file, SUID_MODE) < 0) tst_brkm(TBROK, cleanup, "setuid for setuid_test failed"); SAFE_UMOUNT(cleanup, mntpoint); TEST_PAUSE; }
static void umount2_verify(void) { int ret; char buf[256]; const char *str = "abcdefghijklmnopqrstuvwxyz"; SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL); mount_flag = 1; fd = SAFE_CREAT(cleanup, MNTPOINT "/file", FILE_MODE); TEST(umount2(MNTPOINT, MNT_DETACH)); if (TEST_RETURN != 0) { tst_resm(TFAIL | TTERRNO, "umount2(2) Failed"); goto EXIT; } mount_flag = 0; /* check the unavailability for new access */ ret = access(MNTPOINT "/file", F_OK); if (ret != -1) { tst_resm(TFAIL, "umount2(2) MNT_DETACH flag " "performed abnormally"); goto EXIT; } /* * check the old fd still points to the file * in previous mount point and is available */ SAFE_WRITE(cleanup, 1, fd, str, strlen(str)); SAFE_CLOSE(cleanup, fd); SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL); mount_flag = 1; fd = SAFE_OPEN(cleanup, MNTPOINT "/file", O_RDONLY); memset(buf, 0, sizeof(buf)); SAFE_READ(cleanup, 1, fd, buf, strlen(str)); if (strcmp(str, buf)) { tst_resm(TFAIL, "umount2(2) MNT_DETACH flag " "performed abnormally"); goto EXIT; } tst_resm(TPASS, "umount2(2) Passed"); EXIT: SAFE_CLOSE(cleanup, fd); fd = 0; if (mount_flag) { SAFE_UMOUNT(cleanup, MNTPOINT); mount_flag = 0; } }
static void cleanup(void) { SAFE_MUNMAP(sfile, st.st_size); SAFE_MUNMAP(amem, st.st_size); SAFE_UMOUNT(TMP_DIR); }