Пример #1
0
int getchild(int group, int child, int children)
{
	int pid;

	pid = FORK_OR_VFORK();

	if (pid < 0) {

		massmurder();	/* kill the kids */
		tst_brkm(TBROK, cleanup,
			 "\tFork failed (may be OK if under stress)");
		tst_exit();
	} else if (pid == 0) {	/* child does this */
		switch (children % NCHILD) {
		case 0:
#ifdef UCLINUX
			if (self_exec(argv0, "nd", 1, nfiles) < 0) {
				massmurder();
				tst_brkm(TBROK, cleanup, "\tself_exec failed");
				tst_exit();
			}
#else
			dochild1();	/* create existing directories */
#endif
			break;	/* so lint won't complain */
		case 1:
#ifdef UCLINUX
			if (self_exec(argv0, "n", 2) < 0) {
				massmurder();
				tst_brkm(TBROK, cleanup, "\tself_exec failed");
				tst_exit();
			}
#else
			dochild2();	/* remove nonexistant directories */
#endif
			break;
		case 2:
#ifdef UCLINUX
			if (self_exec(argv0, "nd", 3, group) < 0) {
				massmurder();
				tst_brkm(TBROK, cleanup, "\tself_exec failed");
				tst_exit();
			}
#else
			dochild3(group);	/* create/delete directories */
#endif
			break;
		default:
			tst_brkm(TFAIL, cleanup,
				 "Test not inplemented for child %d", child);
			exit(1);
			break;
		}
		exit(1);	/* If child gets here, something wrong */
	}
	pidlist[children] = pid;
	return 0;
}
Пример #2
0
void dochild2_uclinux(void)
{
	/* Set up to catch SIGTERM signal */
	if (signal(SIGTERM, term) == SIG_ERR) {
		tst_brkm(TFAIL, cleanup,
			 "Error setting up SIGTERM signal, ERRNO = %d", errno);
	}

	dochild2();
}
Пример #3
0
int main(int argc, char *argv[])
{
	int pid;
	sigset_t set;
	struct sigaction act, oact;
	int term();
	int al();
	void dochild1();
	void dochild2();

#ifdef UCLINUX

	tst_parse_opts(argc, argv, NULL, NULL);

	maybe_run_child(&dochild1, "n", 1);
	maybe_run_child(&dochild2, "n", 2);
#endif
	sigemptyset(&set);
	act.sa_handler = (void (*)())term;
	act.sa_mask = set;
	act.sa_flags = 0;
	if (sigaction(SIGTERM, &act, &oact)) {
		tst_brkm(TBROK, NULL, "Sigaction(SIGTERM)");
	}

	sigemptyset(&set);
	act.sa_handler = (void (*)())al;
	act.sa_mask = set;
	act.sa_flags = 0;
	if (sigaction(SIGALRM, &act, 0)) {
		tst_brkm(TBROK, NULL, "Sigaction(SIGALRM)");
	}
	parent_pid = getpid();
	tst_tmpdir();
/*--------------------------------------------------------------*/

	pid = FORK_OR_VFORK();
	if (pid < 0) {
		tst_brkm(TBROK, NULL, "fork() returned %d", pid);
	}
	if (pid == 0) {
#ifdef UCLINUX
		if (self_exec(argv[0], "n", 1) < 0) {
			tst_resm(TBROK, "self_exec failed");
		}
#else
		dochild1();
#endif
	}
	kidpid[0] = pid;
	pid = FORK_OR_VFORK();
	if (pid < 0) {
		(void)kill(kidpid[0], SIGTERM);
		(void)unlink("./rename14");
		tst_brkm(TBROK, NULL, "fork() returned %d", pid);
	}
	if (pid == 0) {
#ifdef UCLINUX
		if (self_exec(argv[0], "n", 1) < 0) {
			tst_resm(TBROK, "self_exec failed");
		}
#else
		dochild2();
#endif
	}
	kidpid[1] = pid;

	alarm(RUNTIME);

	/* Collect child processes. */
	/* Wait for timeout */
	pause();

	kill(kidpid[0], SIGTERM);
	kill(kidpid[1], SIGTERM);

	waitpid(kidpid[0], NULL, 0);
	waitpid(kidpid[1], NULL, 0);

	unlink("./rename14");
	unlink("./rename14xyz");
	(local_flag == PASSED) ? tst_resm(TPASS, "Test Passed")
	    : tst_resm(TFAIL, "Test Failed");

	tst_rmdir();
	tst_exit();
}
Пример #4
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	pid_t pid;
	struct stat buf1;
	int e_code, status, status2;

	/*
	 * parse standard options
	 */
	if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) {
		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
	}
#ifdef UCLINUX
	maybe_run_child(&dochild1, "ns", 1, tstdir2);
	maybe_run_child(&dochild2, "ns", 2, tstdir4);
#endif

	/*
	 * perform global setup for test
	 */
	setup();

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

	/*
	 * check looping state if -i option given
	 */
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		/* reset Tst_count in case we are looping. */
		Tst_count = 0;

//test1:       $
		/*
		 * attempt to rmdir a file whose parent directory has
		 * the sticky bit set without the root right
		 * or effective uid
		 */

		if (stat(tstdir1, &buf1) != -1) {
			tst_brkm(TBROK, cleanup,
				 "tmp directory %s found!", tstdir1);
		 /*NOTREACHED*/}
		/* create a directory */
		if (mkdir(tstdir1, PERMS) == -1) {
			tst_brkm(TBROK, cleanup,
				 "Couldnot create directory %s", tstdir1);
		 /*NOTREACHED*/}
		if (stat(tstdir1, &buf1) == -1) {
			perror("stat");
			tst_brkm(TBROK, cleanup, "failed to stat directory %s "
				 "in rmdir()", tstdir1);
			/* NOTREACHED */
		}
		/* set the sticky bit */
		if (chmod(tstdir1, buf1.st_mode | S_ISVTX) != 0) {
			perror("chmod");
			tst_brkm(TBROK, cleanup,
				 "failed to set the S_ISVTX bit");
			/* NOTREACHED */
		}
		/* create a sub directory under tstdir1 */
		if (mkdir(tstdir2, PERMS) == -1) {
			tst_brkm(TBROK, cleanup,
				 "Could not create directory %s", tstdir2);
		}

		if ((pid = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, cleanup, "fork() failed");
		 /*NOTREACHED*/}

		if (pid == 0) {	/* first child */
#ifdef UCLINUX
			if (self_exec(av[0], "ns", 1, tstdir2) < 0) {
				tst_brkm(TBROK, cleanup, "self_exec failed");
			}
#else
			dochild1();
#endif
		}
		/* Parent */

//test2:       $
		/* create the a directory with 0700 permits */
		if (mkdir(tstdir3, 0700) == -1) {
			tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) Failed",
				 tstdir3, PERMS);
		 /*NOTREACHED*/}
		/* create the a directory with 0700 permits */
		if (mkdir(tstdir4, 0777) == -1) {
			tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) Failed",
				 tstdir4, PERMS);
		 /*NOTREACHED*/}

		if ((pid = FORK_OR_VFORK()) == -1) {
			tst_brkm(TBROK, cleanup, "fork() failed");
		 /*NOTREACHED*/}

		if (pid == 0) {	/* child */
#ifdef UCLINUX
			if (self_exec(av[0], "ns", 2, tstdir4) < 0) {
				tst_brkm(TBROK, cleanup, "self_exec failed");
			}
#else
			dochild2();
#endif
		} else {	/* parent */
			/* wait for the child to finish */
			wait(&status);
			wait(&status2);
			/* make sure the child returned a good exit status */
			e_code = status >> 8;
			if (e_code != 0) {
				tst_resm(TFAIL, "Failures reported above");
			} else {
				/* No error in the 1st one, check the 2nd */
				e_code = status2 >> 8;
				if (e_code != 0) {
					tst_resm(TFAIL,
						 "Failures reported above");
				}
			}
		}

		/* clean up things in case we are looping */

		(void)rmdir(tstdir2);
		(void)rmdir(tstdir1);
		(void)rmdir(tstdir4);
		(void)rmdir(tstdir3);

	}			/* End for TEST_LOOPING */

	/*
	 * cleanup and exit
	 */
	cleanup();

	 /*NOTREACHED*/ return 0;

}				/* End main */