Example #1
0
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);
}
Example #2
0
int main(int argc, char **argv)
{
	int lc;
	char *msg;
	pid_t pid;
	int status;
	int fd;

	if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

#ifdef UCLINUX
	maybe_run_child(&childfunc_uc, "ds", &fd_uc, FILE_NAME);
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		fd = open(FILE_NAME, O_RDWR);

		if (fd == -1)
			tst_brkm(TFAIL, cleanup, "parent failed to open the"
				 "file, errno %d", errno);

		pid = FORK_OR_VFORK();

		if (pid == -1)
			tst_brkm(TFAIL, cleanup, "fork() failed, errno %d",
				 errno);
		if (pid == 0) {
#ifdef UCLINUX
			if (self_exec(argv[0], "ds", fd, FILE_NAME) < 0)
				tst_brkm(TFAIL, cleanup, "self_exec failed, "
					 "errno &d", errno);
#else
			childfunc(fd);
#endif
		}

		TEST(flock(fd, LOCK_EX | LOCK_NB));

		if (TEST_RETURN != 0)
			tst_resm(TFAIL,
				 "Parent: Initial attempt to flock() failed, "
				 "errno %d", TEST_ERRNO);
		else
			tst_resm(TPASS,
				 "Parent: Initial attempt to flock() passed");

		TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint);

		if ((waitpid(pid, &status, 0)) < 0) {
			tst_resm(TFAIL, "wait() failed");
			continue;
		}
		if ((WIFEXITED(status)) && (WEXITSTATUS(status) == 0))
			tst_resm(TPASS, "flock03 Passed");
		else
			tst_resm(TFAIL, "flock03 Failed");

		close(fd);

	}

	cleanup();
	tst_exit();
}
Example #3
0
int main(int ac, char **av)
{
	int child_pid;
	int status;
	int rval;
	int lc;
	const char *msg;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
#ifdef UCLINUX
	maybe_run_child(&do_child, "");
#endif

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		/* Child is in new session we are not alowed to change pgid */
		if ((child_pid = FORK_OR_VFORK()) == -1)
			tst_brkm(TBROK, cleanup, "fork() failed");

		if (child_pid == 0) {
#ifdef UCLINUX
			if (self_exec(av[0], "") < 0)
				tst_brkm(TBROK, cleanup, "self_exec failed");
#else
			do_child();
#endif
		}

		TST_CHECKPOINT_PARENT_WAIT(cleanup, &checkpoint);
		rval = setpgid(child_pid, getppid());
		if (rval == -1 && errno == EPERM) {
			tst_resm(TPASS, "setpgid failed with EPERM");
		} else {
			tst_resm(TFAIL,
				"retval %d, errno %d, expected errno %d",
				rval, errno, EPERM);
		}
		TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint);

		if (wait(&status) < 0)
			tst_resm(TFAIL | TERRNO, "wait() for child 1 failed");

		if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0))
			tst_resm(TFAIL, "child 1 failed with status %d",
				WEXITSTATUS(status));

		/* Child after exec() we are no longer allowed to set pgid */
		if ((child_pid = FORK_OR_VFORK()) == -1)
			tst_resm(TFAIL, "Fork failed");

		if (child_pid == 0) {
			if (execlp(TEST_APP, TEST_APP, NULL) < 0)
				perror("exec failed");

			exit(127);
		}

		TST_CHECKPOINT_PARENT_WAIT(cleanup, &checkpoint);
		rval = setpgid(child_pid, getppid());
		if (rval == -1 && errno == EACCES) {
			tst_resm(TPASS, "setpgid failed with EACCES");
		} else {
			tst_resm(TFAIL,
				"retval %d, errno %d, expected errno %d",
				rval, errno, EACCES);
		}
		TST_CHECKPOINT_SIGNAL_CHILD(cleanup, &checkpoint);

		if (wait(&status) < 0)
			tst_resm(TFAIL | TERRNO, "wait() for child 2 failed");

		if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0))
			tst_resm(TFAIL, "child 2 failed with status %d",
				WEXITSTATUS(status));
	}

	cleanup();
	tst_exit();
}