Beispiel #1
0
int main(int ac, char **av)
{
	int lc, pid;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

#ifdef UCLINUX
	maybe_run_child(&dochild, "sdd", filename, &recstart, &reclen);
#endif

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		sprintf(filename, MOUNT_DIR"%s.%d.%d\n", TCID, getpid(), lc);

		if (tst_fill_file(filename, 0, 1024, 8)) {
			tst_brkm(TBROK, cleanup,
			         "Failed to create test file '%s'", filename);
		}

		SAFE_CHMOD(cleanup, filename, 02666);

		reclen = RECLEN;
		/*
		 * want at least RECLEN bytes BEFORE AND AFTER the
		 * record lock.
		 */
		recstart = RECLEN + rand() % (len - 3 * RECLEN);

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

		if (pid == 0) {
#ifdef UCLINUX
			if (self_exec(av[0], "sdd", filename, recstart,
			              reclen) < -1) {
				tst_brkm(TBROK, cleanup, "self_exec() failed");
			}
#else
			dochild();
#endif
		}

		doparent();
	}

	cleanup();
	tst_exit();
}
Beispiel #2
0
int main(int ac, char **av)
{
	int fd, i;
	int tlen = 0;
	struct sigaction act;
	int lc;
	char *msg;
	struct statvfs fs;

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

	}
#ifdef UCLINUX
	maybe_run_child(&dochild, "dddd", filename, &recstart, &reclen, &ppid);
#endif

	local_flag = PASSED;
	tst_tmpdir();
	if (statvfs(".", &fs) == -1) {
		tst_resm(TFAIL | TERRNO, "statvfs failed");
		tst_rmdir();
		tst_exit();
	}
	if ((fs.f_flag & MS_MANDLOCK) == 0) {
		tst_resm(TCONF,
			 "The filesystem where /tmp is mounted does"
			 " not support mandatory locks. Cannot run this test.");
		tst_rmdir();
		tst_exit();

	}
	for (lc = 0; TEST_LOOPING(lc); lc++) {
		setvbuf(stdin, 0, _IOLBF, BUFSIZ);
		setvbuf(stdout, 0, _IOLBF, BUFSIZ);
		setvbuf(stderr, 0, _IOLBF, BUFSIZ);
		ppid = getpid();
		srand(ppid);
		sigemptyset(&set);
		act.sa_handler = (void (*)())usr1hndlr;
		act.sa_mask = set;
		act.sa_flags = 0;
		if (sigaction(SIGUSR1, &act, 0)) {
			tst_resm(TBROK, "Sigaction for SIGUSR1 failed");
			tst_rmdir();
			tst_exit();
		}		/* end if */
		if (sigaddset(&set, SIGUSR1)) {
			tst_resm(TBROK, "sigaddset for SIGUSR1 failed");
			tst_rmdir();
			tst_exit();
		}
		if (sigprocmask(SIG_SETMASK, &set, 0)) {
			tst_resm(TBROK, "sigprocmask for SIGUSR1 failed");
			tst_rmdir();
			tst_exit();
		}
		for (i = 0; i < iterations; i++) {
			sprintf(filename, "%s.%d.%d\n", progname, ppid, i);
			if ((fd = open(filename, O_CREAT | O_RDWR, 02666)) < 0) {
				tst_resm(TBROK,
					 "parent error opening/creating %s",
					 filename);
				cleanup();
			}	/* end if */
			if (chown(filename, geteuid(), getegid()) == -1) {
				tst_resm(TBROK, "parent error chowning %s",
					 filename);
				cleanup();
			}	/* end if */
			if (chmod(filename, 02666) == -1) {
				tst_resm(TBROK, "parent error chmoding %s",
					 filename);
				cleanup();
			}	/* end if */
			do {
				if (write(fd, buffer, BUFSIZE) < 0) {
					tst_resm(TBROK,
						 "parent write failed to %s",
						 filename);
					cleanup();
				}
				tlen += BUFSIZE;
			} while (tlen < len);
			close(fd);
			reclen = RECLEN;
			/*
			 * want at least RECLEN bytes BEFORE AND AFTER the
			 * record lock.
			 */
			recstart = RECLEN + rand() % (len - 3 * RECLEN);

			if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1)
				tst_brkm(TBROK, cleanup,
					 "sync_pipe_create failed");

			if ((cpid = FORK_OR_VFORK()) < 0) {
				unlink(filename);
				tst_resm(TINFO,
					 "System resource may be too low, fork() malloc()"
					 " etc are likely to fail.");
				tst_resm(TBROK,
					 "Test broken due to inability of fork.");
				tst_rmdir();
				tst_exit();
			}

			if (cpid == 0) {
#ifdef UCLINUX
				if (self_exec
				    (av[0], "dddd", filename, recstart, reclen,
				     ppid) < -1) {
					unlink(filename);
					tst_resm(TBROK, "self_exec failed.");
					tst_rmdir();
					tst_exit();
				}
#else
				dochild();
#endif
				/* never returns */
			}

			if (sync_pipe_wait(sync_pipes) == -1)
				tst_brkm(TBROK, cleanup,
					 "sync_pipe_wait failed");

			if (sync_pipe_close(sync_pipes, PIPE_NAME) == -1)
				tst_brkm(TBROK, cleanup,
					 "sync_pipe_close failed");

			doparent();
			/* child should already be dead */
			unlink(filename);
		}
		if (local_flag == PASSED)
			tst_resm(TPASS, "Test passed.");
		else
			tst_resm(TFAIL, "Test failed.");

		tst_rmdir();
		tst_exit();
	}			/* end for */
	tst_exit();
}