예제 #1
0
int main(int argc, char **argv)
{
	int fd, pf[2], pid;

	test_init(argc, argv);

	pipe(pf);

	fd = open(filename, O_CREAT | O_RDWR, 0600);
	if (fd < 0) {
		err("No file");
		return -1;
	}

	flock(fd, LOCK_EX);

	pid = fork();
	if (pid == 0) {
		close(pf[1]);
		read(pf[0], &pid, sizeof(pid));
		exit(0);
	}

	close(pf[0]);
	close(fd);

	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		err("No file 2");
		close(pf[1]);
		waitpid(pid, NULL, 0);
		return -1;
	}

	if (flock(fd, LOCK_EX | LOCK_NB) == 0) {
		err("Bogus locks");
		close(pf[1]);
		waitpid(pid, NULL, 0);
		return -1;
	}

	test_daemon();
	test_waitsig();

	if (check_file_locks(pid, fd))
		pass();
	else
		fail("Flock file locks check failed");

	close(pf[1]);
	waitpid(pid, NULL, 0);
	close(fd);
	unlink(filename);

	return 0;
}
예제 #2
0
int main(int argc, char **argv)
{
	int fd, child_fd, pid;

	test_init(argc, argv);

	fd = child_fd = open(filename, O_CREAT | O_RDWR, 0600);
	if (fd < 0) {
		pr_perror("No file");
		return -1;
	}

	flock(fd, LOCK_EX);

	pid = fork();
	if (pid == 0) {
		test_waitsig();
		exit(0);
	}

	close(fd);

	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		pr_perror("No file 2");
		kill(pid, SIGTERM);
		waitpid(pid, NULL, 0);
		return -1;
	}

	if (flock(fd, LOCK_EX | LOCK_NB) == 0) {
		pr_perror("Bogus locks");
		kill(pid, SIGTERM);
		waitpid(pid, NULL, 0);
		return -1;
	}

	test_daemon();
	test_waitsig();

	if (check_file_locks(pid, fd, child_fd) > 0)
		pass();
	else
		fail("Flock file locks check failed");

	kill(pid, SIGTERM);
	waitpid(pid, NULL, 0);
	close(fd);
	unlink(filename);

	return 0;
}
예제 #3
0
int main(int argc, char **argv)
{
	int fd_0, fd_1, fd_2;

	test_init(argc, argv);

	m = get_cwd_mnt_info();
	if (!m) {
		pr_perror("Can't fetch mountinfo");
		return -1;
	}
	if (!strcmp(m->fsname, "btrfs"))
		m->s_dev = kdev_to_odev(m->s_dev);

	if (open_all_files(&fd_0, &fd_1, &fd_2))
		return -1;

	flock(fd_0, LOCK_SH);
	flock(fd_1, LOCK_EX);
	flock(fd_2, LOCK_MAND | LOCK_READ);

	test_daemon();
	test_waitsig();

	if (check_file_locks())
		fail("Flock file locks check failed");
	else
		pass();

	close(fd_0);
	close(fd_1);
	close(fd_2);
	unlink(file0);
	unlink(file1);
	unlink(file2);

	return 0;
}