Пример #1
0
int child_func(void *arg)
{
	int ret = 0;

	/* makes mount DIRA a slave of DIRA (all slave mounts have
	 * a master mount which is a shared mount) */
	if (mount("none", DIRA, "none", MS_SLAVE, NULL) == -1) {
		perror("mount");
		return 1;
	}

	TST_CHECKPOINT_SIGNAL_PARENT(&checkpoint1);
	TST_CHECKPOINT_CHILD_WAIT(&checkpoint2);

	/* checks that shared mounts propagates to slave mount */
	if (access(DIRA"/B", F_OK) == -1)
		ret = 2;

	TST_CHECKPOINT_SIGNAL_PARENT(&checkpoint1);
	TST_CHECKPOINT_CHILD_WAIT(&checkpoint2);

	/* bind mounts DIRB to DIRA making contents of DIRB visible
	 * in DIRA */
	if (mount(DIRB, DIRA, "none", MS_BIND, NULL) == -1) {
		perror("mount");
		return 1;
	}

	TST_CHECKPOINT_SIGNAL_PARENT(&checkpoint1);
	TST_CHECKPOINT_CHILD_WAIT(&checkpoint2);

	umount(DIRA);
	return ret;
}
Пример #2
0
int main(void)
{
	int pid;
	struct tst_checkpoint checkpoint;

	tst_tmpdir();

	TST_CHECKPOINT_CREATE(&checkpoint);

	pid = fork();

	switch (pid) {
	case -1:
		tst_brkm(TBROK | TERRNO, NULL, "Fork failed");
	break;
	case 0:
		TST_CHECKPOINT_CHILD_WAIT(&checkpoint);
		fprintf(stderr, "Child: checkpoint reached\n");
		exit(0);
	break;
	default:
		fprintf(stderr, "Parent: exiting without signaling\n");
		tst_rmdir();
		exit(0);
	break;
	}
		
	return 0;
}
Пример #3
0
static void do_child(void)
{
	if (setsid() < 0) {
		printf("CHILD: setsid() failed, errno: %d\n", errno);
		exit(2);
	}

	TST_CHECKPOINT_SIGNAL_PARENT(&checkpoint);

	TST_CHECKPOINT_CHILD_WAIT(&checkpoint);

	exit(0);
}
Пример #4
0
static void childfunc(int fd)
{
	int fd2;

	TST_CHECKPOINT_CHILD_WAIT(&checkpoint);

	fd2 = open(FILE_NAME, O_RDWR);

	if (fd2 == -1) {
		fprintf(stderr, "CHILD: failed to open the file: %s\n",
		        strerror(errno));
		exit(1);
	}

	if (flock(fd2, LOCK_EX | LOCK_NB) != -1) {
		fprintf(stderr, "CHILD: The file was not already locked\n");
		exit(1);
	}

	TEST(flock(fd, LOCK_UN));
	/* XXX: LOCK_UN does not return an error if there was nothing to
	 * unlock.
	 */
	if (TEST_RETURN == -1) {
		fprintf(stderr, "CHILD: Unable to unlock file locked by "
		        "parent: %s\n", strerror(TEST_ERRNO));
		exit(1);
	} else {
		fprintf(stderr, "CHILD: File locked by parent unlocked\n");
	}

	TEST(flock(fd2, LOCK_EX | LOCK_NB));

	if (TEST_RETURN == -1) {
		fprintf(stderr, "CHILD: Unable to lock file after "
		        "unlocking: %s\n", strerror(TEST_ERRNO));
		exit(1);
	} else {
		fprintf(stderr, "CHILD: Locking after unlock passed\n");
	}

	close(fd);
	close(fd2);

	exit(0);
}