示例#1
0
/*
 * do_child()
 */
void do_child(int i)
{
#ifdef UCLINUX
	if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1)
		tst_brkm(TBROK, cleanup, "sync_pipe_create failed");
#endif
	if (sync_pipe_notify(sync_pipes) == -1)
		tst_brkm(TBROK, cleanup, "sync_pipe_notify failed: %d", errno);

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

	/*
	 * make the call with the TEST macro
	 */

	TEST(semop(sem_id_1, &s_buf, 1));

	if (TEST_RETURN != -1) {
		tst_resm(TFAIL, "call succeeded when error expected");
		exit(-1);
	}

	TEST_ERROR_LOG(TEST_ERRNO);

	if (TEST_ERRNO == TC[i].error) {
		tst_resm(TPASS, "expected failure - errno = %d"
			 " : %s", TEST_ERRNO, strerror(TEST_ERRNO));
	} else {
		tst_resm(TFAIL, "unexpected error - "
			 "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
	}

	exit(0);
}
示例#2
0
void do_child_1()
{
	int fildes;

#ifdef UCLINUX
	if (sync_pipe_create(start_sync_pipes, PIPE_NAME_START) == -1)
		tst_brkm(TBROK, cleanup, "sync_pipe_create failed");
	if (sync_pipe_create(end_sync_pipes, PIPE_NAME_END) == -1)
		tst_brkm(TBROK, cleanup, "sync_pipe_create failed");
#endif

	if ((fildes = open(test_app, O_WRONLY)) == -1) {
		printf("%s\n", test_app);
		perror("open failed");
		exit(1);
	}

	if (sync_pipe_notify(start_sync_pipes) == -1) {
		perror("sync_pipe_notify failed");
		exit(1);
	}

	if (sync_pipe_close(start_sync_pipes, PIPE_NAME_START) == -1) {
		perror("sync_pipe_close failed");
		exit(1);
	}

	if (sync_pipe_wait(end_sync_pipes) == -1) {
		perror("sync_pipe_wait failed");
		exit(1);
	}
	exit(0);
}
示例#3
0
文件: msgrcv05.c 项目: GOEUM/ltp
void do_child(void)
{
    if (sync_pipe_notify(sync_pipes) == -1)
        tst_brkm(TBROK, cleanup, "sync_pipe_notify failed");

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

    TEST(msgrcv(msg_q_1, &rcv_buf, MSGSIZE, 1, 0));

    if (TEST_RETURN != -1)
        tst_brkm(TFAIL, NULL, "call succeeded unexpectedly");

    switch (TEST_ERRNO) {
    case EINTR:
        tst_resm(TPASS, "got EINTR as expected");
        break;
    default:
        tst_resm(TFAIL | TTERRNO,
                 "call failed with an unexpected error");
        break;
    }

    exit(0);
}
示例#4
0
文件: msgsnd06.c 项目: Nan619/ltp-ddt
/*
 * do_child()
 */
void do_child()
{
	int retval = 0;

#ifdef UCLINUX
	/* initialize the message buffer */
	init_buf(&msg_buf, MSGTYPE, MSGSIZE);

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

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

	if (sync_pipe_close(sync_pipes, PIPE_NAME) == -1)
		tst_brkm(TBROK, cleanup, "sync_pipe_close failed");
	/*
	 * Attempt to write another message to the full queue.
	 * Without the IPC_NOWAIT flag, the child sleeps
	 */
	TEST(msgsnd(msg_q_1, &msg_buf, MSGSIZE, 0));

	if (TEST_RETURN != -1) {
		retval = 1;
		tst_resm(TFAIL, "call succeeded when error expected");
		exit(retval);
	}

	TEST_ERROR_LOG(TEST_ERRNO);

	switch (TEST_ERRNO) {
	case EIDRM:
		tst_resm(TPASS, "expected failure - errno = %d : %s",
			 TEST_ERRNO, strerror(TEST_ERRNO));

		/* mark the queue as invalid as it was removed */
		msg_q_1 = -1;
		break;
	default:
		retval = 1;
		tst_resm(TFAIL,
			 "call failed with an unexpected error - %d : %s",
			 TEST_ERRNO, strerror(TEST_ERRNO));
		break;
	}
	exit(retval);
}
示例#5
0
文件: ftruncate04.c 项目: GOEUM/ltp
void dochild(void)
{
	int fd;
	struct flock flocks;

#ifdef UCLINUX
#define PIPE_NAME	"ftruncate04"
	if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1)
		tst_brkm(TBROK, cleanup, "sync_pipe_create failed");
#endif

	if ((fd = open(filename, O_RDWR)) < 0) {
		tst_resm(TFAIL, "child open");
		tst_exit();
	}
	lseek(fd, 0, SEEK_SET);
	flocks.l_type = F_WRLCK;
	flocks.l_whence = SEEK_CUR;
	flocks.l_start = recstart;
	flocks.l_len = reclen;
	if (fcntl(fd, F_SETLKW, &flocks) < 0) {
		tst_resm(TFAIL, "child fcntl failed");
		tst_exit();
	}

	if (kill(ppid, SIGUSR1) < 0) {
		tst_resm(TFAIL, "child kill");
		tst_exit();
	}

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

	if (sync_pipe_close(sync_pipes, PIPE_NAME) == -1)
		tst_brkm(TBROK, cleanup, "sync_pipe_close failed");
	pause();
	tst_exit();
}
示例#6
0
/*
 * do_child()
 */
void do_child()
{
	if (sync_pipe_notify(sync_pipes) == -1)
		tst_brkm(TBROK, cleanup, "sync_pipe_notify failed");

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

	TEST(msgrcv(msg_q_1, &rcv_buf, MSGSIZE, 1, 0));

	if (TEST_RETURN != -1) {
		tst_resm(TFAIL, "call succeeded when error expected");
		exit(-1);
	}

	TEST_ERROR_LOG(TEST_ERRNO);

	switch (TEST_ERRNO) {
	case EIDRM:
		tst_resm(TPASS, "expected failure - errno = %d : %s",
			 TEST_ERRNO, strerror(TEST_ERRNO));

		/* mark the queue as invalid as it was removed */
		msg_q_1 = -1;
		break;
	default:
		tst_resm(TFAIL,
			 "call failed with an unexpected error - %d : %s",
			 TEST_ERRNO, strerror(TEST_ERRNO));
		break;
	}

	/* if it exists, remove the message queue that was created */
	rm_queue(msg_q_1);

	exit(0);
}
示例#7
0
/*
 * do_child
 */
void do_child()
{
	int rval;
	void *test;

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

	if (stat_time == FIRST) {
		test = set_shmat();
	} else {
		test = set_shared;
	}

	if (sync_pipe_notify(sync_pipes) == -1)
		tst_brkm(TBROK, cleanup, "sync_pipe_notify failed");
#ifdef UCLINUX
	if (sync_pipe_close(sync_pipes, NULL) == -1)
#else
	if (sync_pipe_close(sync_pipes, PIPE_NAME) == -1)
#endif
		tst_brkm(TBROK, cleanup, "sync_pipe_close failed");

	/* do an assignement for fun */
	memcpy(test, &stat_i, sizeof(stat_i));

	/* pause until we get a signal from stat_cleanup() */
	rval = pause();

	/* now we're back - detach the memory and exit */
	if (shmdt(test) == -1) {
		tst_resm(TBROK, "shmdt() failed - %d", errno);
	}
	tst_exit();
}
示例#8
0
int main(int ac, char **av)
{
	int lc;
	char *msg;
	pid_t pid, pid1;
	int retval = 3, status;
	char *argv[1], *env[1];

	if ((msg = parse_opts(ac, av, options, &help)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
#ifdef UCLINUX
	maybe_run_child(&do_child_1, "nS", 1, &test_app);
#endif

	if (!Fflag)
		tst_brkm(TBROK, NULL,
		    "You must specify an executable file with the -F option.");

	setup(*av);

	TEST_EXP_ENOS(exp_enos);

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		if (sync_pipe_create(start_sync_pipes, PIPE_NAME_START) == -1)
			tst_brkm(TBROK, cleanup, "sync_pipe_create failed");
		if (sync_pipe_create(end_sync_pipes, PIPE_NAME_END) == -1)
			tst_brkm(TBROK, cleanup, "sync_pipe_create failed");

		/*
		 * to test whether execve(2) sets ETXTBSY when a second
		 * child process attempts to execve the executable opened
		 * by the first child process
		 */
		if ((pid = FORK_OR_VFORK()) == -1)
			tst_brkm(TBROK, cleanup, "fork #1 failed");
		else if (pid == 0) {
#ifdef UCLINUX
			if (self_exec(av[0], "nS", 1, test_app) < 0)
				tst_brkm(TBROK, cleanup, "self_exec failed");
#else
			do_child_1();
#endif
		}

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

		if (sync_pipe_close(start_sync_pipes, PIPE_NAME_START) == -1)
			tst_brkm(TBROK, cleanup, "sync_pipe_close failed");

		if ((pid1 = FORK_OR_VFORK()) == -1)
			tst_brkm(TBROK, cleanup, "fork #2 failed");

		if (pid1 == 0) {

			retval = 3;

			argv[0] = 0;
			env[0] = 0;

			/* do not interfere with end synchronization of first
			 * child */
			sync_pipe_close(end_sync_pipes, PIPE_NAME_END);

			TEST(execve(test_app, argv, env));

			TEST_ERROR_LOG(TEST_ERRNO);

			if (TEST_ERRNO != ETXTBSY) {
				retval = 1;
				perror("didn't get ETXTBSY\n");
			} else
				printf("execve failed with ETXTBSY as "
				    "expected\n");
			exit(retval);
		}
		/* wait for the child to finish */
		if (waitpid(pid1, &status, 0) == -1)
			tst_brkm(TBROK|TERRNO, cleanup, "waitpid failed");
		if (WIFEXITED(status) && WEXITSTATUS(status) == 3)
			tst_resm(TPASS, "execve failed as expected");
		else
			tst_resm(TFAIL, "execve succeeded, expected failure");

		/*  terminate first child */
		sync_pipe_notify(end_sync_pipes);
		(void) waitpid(pid, NULL, 0);
	}
	cleanup();

	tst_exit();
}