Exemplo n.º 1
0
Arquivo: ftest02.c Projeto: 1587/ltp
/*
 * fussdir()
 *	Make a directory, put stuff in it, remove it, and remove directory.
 *
 * Randomly leave the directory there.
 */
static void fussdir(int me, int count)
{
	int val;
	char dir[MAXPATHLEN], fname[MAXPATHLEN], savedir[MAXPATHLEN];

	ft_mkname(dir, dirname, me, count);
	rmdir(dir);
	unlink(dir);

	val = mkdir(dir, 0755);
	warn(val, "mkdir", dir);

	/*
	 * Arrange to create files in the directory.
	 */
	strcpy(savedir, dirname);
	strcpy(dirname, "");

	val = chdir(dir);
	warn(val, "chdir", dir);

	crfile(me, count);
	crfile(me, count + 1);

	val = chdir("..");
	warn(val, "chdir", "..");

	val = rmdir(dir);

	if (val >= 0) {
		tst_brkm(TFAIL, NULL,
			 "Test[%d]: rmdir of non-empty %s succeeds!", me,
			 dir);
	}

	val = chdir(dir);
	warn(val, "chdir", dir);

	ft_mkname(fname, dirname, me, count);
	val = unlink(fname);
	warn(val, "unlink", fname);

	ft_mkname(fname, dirname, me, count + 1);
	val = unlink(fname);
	warn(val, "unlink", fname);

	val = chdir(homedir);
	warn(val, "chdir", homedir);

	if (rand() & 0x01) {
		val = rmdir(dir);
		warn(val, "rmdir", dir);
	}

	strcpy(dirname, savedir);
}
Exemplo n.º 2
0
Arquivo: ftest02.c Projeto: 1587/ltp
static void crfile(int me, int count)
{
	int fd, val;
	char fname[MAXPATHLEN], buf[MAXPATHLEN];

	ft_mkname(fname, dirname, me, count);

	fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
	if (fd < 0 && errno == EISDIR) {
		val = rmdir(fname);
		warn(val, "rmdir", fname);
		fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0666);
	}
	warn(fd, "creating", fname);

	val = lseek(fd, (rand() % M), 0);
	warn(val, "lseek", 0);

	val = write(fd, crmsg, sizeof(crmsg) - 1);
	warn(val, "write", 0);

	val = lseek(fd, -(sizeof(crmsg) - 1), 1);
	warn(val, "lseek", 0);

	val = read(fd, buf, sizeof(crmsg) - 1);
	warn(val, "read", 0);

	if (strncmp(crmsg, buf, sizeof(crmsg) - 1))
		dowarn(me, "compare", 0);

	val = close(fd);
	warn(val, "close", 0);
}
Exemplo n.º 3
0
/*
 * unlfile()
 *	Unlink some of the files.
 */
static void unlfile(int me, int count)
{
	int val, i;
	char fname[MAXPATHLEN];

	i = count - 10;
	if (i < 0)
		i = 0;
	for (; i < count; i++) {
		ft_mkname(fname, dirname, me, i);
		val = rmdir(fname);
		if (val < 0)
			val = unlink(fname);
		if (val == 0 || errno == ENOENT)
			continue;
		dowarn(me, "unlink", fname);
	}
}
Exemplo n.º 4
0
Arquivo: ftest02.c Projeto: 1587/ltp
int main(void)
{
	int k, j, pid, child, status, count;
	char name[128];

	/*
	 * Default values for run conditions.
	 */
	iterations = 50;
	nchild = 5;

	if (signal(SIGTERM, term) == SIG_ERR) {
		tst_resm(TFAIL, "first signal failed");

	}

	/*
	 * Make a directory to do this in; ignore error if already exists.
	 */
	local_flag = PASSED;
	parent_pid = getpid();
	tst_tmpdir();

	if (!startdir[0]) {
		if (getcwd(startdir, MAXPATHLEN) == NULL) {
			tst_resm(TBROK, "getcwd failed");

		}
	}
	cwd = startdir;
	strcat(dirname, cwd);
	sprintf(tmpname, "/ftest02.%d", getpid());
	strcat(dirname, tmpname);
	strcat(homedir, cwd);
	sprintf(tmpname, "/ftest02h.%d", getpid());
	strcat(homedir, tmpname);

	mkdir(dirname, 0755);
	mkdir(homedir, 0755);
	if (chdir(dirname) < 0) {
		tst_resm(TBROK, "\tCan't chdir(%s), error %d.", dirname, errno);
		cleanup();

	}
	dirlen = strlen(dirname);
	if (chdir(homedir) < 0) {
		tst_resm(TBROK, "\tCan't chdir(%s), error %d.", homedir, errno);
		cleanup();

	}

	for (k = 0; k < nchild; k++) {
		if ((child = fork()) == 0) {
			dotest(k, iterations);
			exit(0);
		}
		if (child < 0) {
			tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
		}
		pidlist[k] = child;
	}

	/*
	 * Wait for children to finish.
	 */
	count = 0;
	while ((child = wait(&status)) > 0) {
		//tst_resm(TINFO,"Test{%d} exited status = 0x%x", child, status);
		//tst_resm(TINFO,"status is %d",status);
		if (status) {
			tst_resm(TFAIL, "Test{%d} failed, expected 0 exit.",
				 child);
			local_flag = FAILED;
		}
		++count;
	}

	/*
	 * Should have collected all children.
	 */
	if (count != nchild) {
		tst_resm(TFAIL, "Wrong # children waited on, count = %d",
			 count);
		local_flag = FAILED;
	}

	if (local_flag == FAILED)
		tst_resm(TFAIL, "Test failed in fork-wait part.");
	else
		tst_resm(TPASS, "Test passed in fork-wait part.");

	if (iterations > 26)
		iterations = 26;

	for (k = 0; k < nchild; k++)
		for (j = 0; j < iterations + 1; j++) {
			ft_mkname(name, dirname, k, j);
			rmdir(name);
			unlink(name);
		}

	chdir(startdir);

	pid = fork();

	if (pid < 0) {
		tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
	}

	if (pid == 0) {
		execl("/bin/rm", "rm", "-rf", homedir, NULL);
		exit(1);
	} else
		wait(&status);

	if (status)
		tst_resm(TINFO,
			 "CAUTION - ftest02, '%s' may not have been removed.",
			 homedir);

	pid = fork();

	if (pid < 0) {
		tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
	}

	if (pid == 0) {
		execl("/bin/rm", "rm", "-rf", dirname, NULL);
		exit(1);
	} else
		wait(&status);

	if (status) {
		tst_resm(TINFO,
			 "CAUTION - ftest02, '%s' may not have been removed.",
			 dirname);
	}

	sync();

	cleanup();

	tst_exit();
}
Exemplo n.º 5
0
int main(int ac, char *av[])
{
	int pid, child, status, count, k, j;
	char name[3];

	int lc;
	char *msg;

	/*
	 * parse standard options
	 */
	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	}

	/*
	 * Default values for run conditions.
	 */
	iterations = 50;
	nchild = 5;

	if (signal(SIGTERM, term) == SIG_ERR) {
		tst_resm(TBROK,"first signal failed");

	}

	/* use the default values for run conditions */
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		local_flag = PASSED;
		/*
		 * Make a directory to do this in; ignore error if already exists.
		 */
		parent_pid = getpid();
		tst_tmpdir();

		if (!startdir[0]) {
			if (getcwd(startdir, MAXPATHLEN) == NULL) {
				tst_brkm(TFAIL|TERRNO, NULL, "getcwd failed");
			}
		}
		cwd = startdir;
		strcat(dirname, cwd);
		sprintf(tmpname, "/ftest06.%d", getpid());
		strcat(dirname, tmpname);
		strcat(homedir, cwd);
		sprintf(tmpname, "/ftest06h.%d", getpid());
		strcat(homedir, tmpname);

		mkdir(dirname, 0755);
		mkdir(homedir, 0755);
		if (chdir(dirname) < 0) {
			tst_brkm(TFAIL|TERRNO, cleanup, "\tCan't chdir(%s)", dirname);
		}
		dirlen = strlen(dirname);
		if (chdir(homedir) < 0) {
			tst_brkm(TFAIL|TERRNO, cleanup, "\tCan't chdir(%s)", homedir);
		}

		/* enter block */
		for (k = 0; k < nchild; k++) {
			if ((child = fork()) == 0) {
				dotest(k, iterations);

			}
			if (child < 0) {
				tst_brkm(TBROK|TERRNO, cleanup, "fork failed");
			}
			pidlist[k] = child;
		}

		/*
		 * Wait for children to finish.
		 */
		count = 0;
		while ((child = wait(&status)) > 0) {
			//tst_resm(TINFO,"Test{%d} exited status = 0x%x", child, status);
			//fprintf(stdout, "status is %d",status);
			if (status) {
				tst_resm(TFAIL,"Test{%d} failed, expected 0 exit.", child);
				local_flag = FAILED;
			}
			++count;
		}

		/*
		 * Should have collected all children.
		 */
		if (count != nchild) {
			tst_resm(TFAIL,"Wrong # children waited on, count = %d", count);
			local_flag = FAILED;
		}

		if (local_flag == PASSED)
			tst_resm(TPASS, "Test passed.");
		else
			tst_resm(TFAIL, "Test failed.");

		if (iterations > 26)
			iterations = 26;

		for (k = 0; k < nchild; k++)
			for (j = 0; j < iterations + 1; j++) {
				ft_mkname(name, dirname, k, j);
				rmdir(name);
				unlink(name);
			}

		chdir(startdir);

		pid = fork();
		if (pid < 0) {
			tst_brkm(TBROK|TERRNO, NULL, "fork failed");
		}

		if (pid == 0) {
			execl("/bin/rm", "rm", "-rf", homedir, NULL);

		} else
			wait(&status);

		if (status)
			tst_resm(TINFO,"CAUTION - ftest06, '%s' may not have been removed.",
			  homedir);

		pid = fork();
		if (pid < 0) {
			tst_brkm(TBROK|TERRNO, NULL, "fork failed");
		}
		if (pid == 0) {
			execl("/bin/rm", "rm", "-rf", dirname, NULL);
			exit(1);
		} else
			wait(&status);
		if (status) {
			tst_resm(TWARN, "CAUTION - ftest06, '%s' may not have been removed.",
			  dirname);
		}

		sync();
		cleanup();

	}

	if (local_flag == FAILED)
		tst_resm(TFAIL, "Test failed.");
	else
		tst_resm(TPASS, "Test passed.");

	cleanup();
	tst_exit();
}