예제 #1
0
static
void
wait_siblings(void)
{
	int pids[2], fd, rv, x;

	/* Note: this may also blow up if FS synchronization is substandard */

	fd = open_testfile(NULL);
	if (fd<0) {
		return;
	}

	pids[0] = fork();
	if (pids[0]<0) {
		warn("UH-OH: can't fork");
		return;
	}
	if (pids[0]==0) {
		close(fd);
		wait_siblings_child();
		_exit(0);
	}

	pids[1] = fork();
	if (pids[1]<0) {
		warn("UH-OH: can't fork");
		/* abandon the other child process :( */
		return;
	}
	if (pids[1]==0) {
		close(fd);
		wait_siblings_child();
		_exit(0);
	}

	rv = write(fd, pids, sizeof(pids));
	if (rv < 0) {
		warn("UH-OH: write error on %s", TESTFILE);
		/* abandon child procs :( */
		return;
	}
	if (rv != (int)sizeof(pids)) {
		warnx("UH-OH: write error on %s: short count", TESTFILE);
		/* abandon child procs :( */
		return;
	}

	rv = waitpid(pids[0], &x, 0);
	if (rv<0) {
		warn("UH-OH: error waiting for child 0 (pid %d)", pids[0]);
	}
	rv = waitpid(pids[1], &x, 0);
	if (rv<0) {
		warn("UH-OH: error waiting for child 1 (pid %d)", pids[1]);
	}
	warnx("passed: siblings wait for each other");
	close(fd);
	remove(TESTFILE);
}
예제 #2
0
static
int
wait_siblings(void)
{
	pid_t pids[2];
	int rv, fd, semfd, x;
	int bad = 0;
	char semname[32];
	int result;

	/* This test may also blow up if FS synchronization is substandard */

	report_begin("siblings wait for each other");
	report_hassubs();

	snprintf(semname, sizeof(semname), "sem:badcall.%d", (int)getpid());
	semfd = open(semname, O_WRONLY|O_CREAT|O_TRUNC, 0664);
	if (semfd < 0) {
		report_warn("can't make semaphore");
		report_aborted(&result);
		return result;
	}

	fd = open_testfile(NULL);
	if (fd<0) {
		report_aborted(&result);
		close(semfd);
		remove(semname);
		return result;
	}

	pids[0] = fork();
	if (pids[0]<0) {
		report_warn("can't fork");
		report_aborted(&result);
		close(fd);
		close(semfd);
		remove(semname);
		return result;
	}
	if (pids[0]==0) {
		close(fd);
		close(semfd);
		wait_siblings_child(semname);
		_exit(0);
	}

	pids[1] = fork();
	if (pids[1]<0) {
		report_warn("can't fork");
		report_aborted(&result);
		/* abandon the other child process :( */
		close(fd);
		close(semfd);
		remove(semname);
		return result;
	}
	if (pids[1]==0) {
		close(fd);
		close(semfd);
		wait_siblings_child(semname);
		_exit(0);
	}

	rv = write(fd, pids, sizeof(pids));
	if (rv < 0) {
		report_warn("write error on %s", TESTFILE);
		report_aborted(&result);
		/* abandon child procs :( */
		close(fd);
		close(semfd);
		remove(semname);
		return result;
	}
	if (rv != (int)sizeof(pids)) {
		report_warnx("write error on %s: short count", TESTFILE);
		report_aborted(&result);
		/* abandon child procs :( */
		close(fd);
		close(semfd);
		remove(semname);
		return result;
	}

	/* gate the child procs */
	rv = write(semfd, "  ", 2);
	if (rv < 0) {
		report_warn("%s: write", semname);
		bad = 1;
	}

	report_beginsub("overall");
	rv = waitpid(pids[0], &x, 0);
	if (rv<0) {
		report_warn("error waiting for child 0 (pid %d)", pids[0]);
		bad = 1;
	}
	rv = waitpid(pids[1], &x, 0);
	if (rv<0) {
		report_warn("error waiting for child 1 (pid %d)", pids[1]);
		bad = 1;
	}
	if (bad) {
		/* XXX: aborted, or failure, or what? */
		report_aborted(&result);
	}
	else {
		report_passed(&result);
	}
	close(fd);
	close(semfd);
	remove(semname);
	remove(TESTFILE);

	return result;
}