Example #1
0
int main()
{
    char mqname[NAMESIZE];
    mqd_t mqdes;
    struct sigevent notification;
    int pid;
    int status;

    sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid());

    mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0);
    if (mqdes == (mqd_t)-1) {
        perror(ERROR_PREFIX "mq_open");
        return PTS_UNRESOLVED;
    }

    notification.sigev_notify = SIGEV_SIGNAL;
    notification.sigev_signo = SIGUSR1;
    if (mq_notify(mqdes, &notification) != 0) {
        printf("Test FAILED \n");
        mqclean(mqdes, mqname);
        return PTS_FAIL;
    }
    pid = fork();
    if (pid == -1) {
        perror(ERROR_PREFIX "fork");
        mqclean(mqdes, mqname);
        return PTS_UNRESOLVED;
    }
    if (pid == 0) {
        //child process
        if (mq_notify(mqdes, &notification) == -1) {
            if (EBUSY == errno) {
                printf("Test PASSED \n");
                return PTS_PASS;
            }
            else {
                printf("errno != EBUSY \n");
                printf("Test FAILED \n");
                return PTS_FAIL;
            }
        }
        else {
            printf("Test FAILED \n");
            return PTS_FAIL;
        }
    }
    else {
        //parent process
        wait(&status);
        mqclean(mqdes, mqname);
        return status;
    }
}
Example #2
0
int main()
{
	char mqname[NAMESIZE];
        mqd_t mqdes;
        const char s_msg_ptr[MSG_SIZE] = "test message \n";
        struct sigevent notification;
        struct sigaction sa;
        unsigned int prio = 1;

        sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid());
        mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0);
        if (mqdes == (mqd_t)-1) {
                perror(ERROR_PREFIX "mq_open");
                return PTS_UNRESOLVED;
        }
	notification.sigev_notify = SIGEV_SIGNAL;
        notification.sigev_signo = SIGUSR1;
        sa.sa_handler = msg_handler;
        sa.sa_flags = 0;
        sigaction(SIGUSR1, &sa, NULL);
        if (mq_notify(mqdes, &notification) != 0) {
                perror(ERROR_PREFIX "mq_notify");
		mqclean(mqdes, mqname);
                return PTS_UNRESOLVED;
        }
	if (mq_notify(mqdes, NULL) != 0 ) {
		printf("Test FAILED \n");
		mqclean(mqdes, mqname);
		return PTS_FAIL;
	}
        if (mq_send(mqdes, s_msg_ptr, MSG_SIZE, prio) == -1) {
        	perror(ERROR_PREFIX "mq_send");
		mqclean(mqdes, mqname);
        	return PTS_UNRESOLVED;
        }
	sleep(1);
	if (mq_unlink(mqname) != 0) {
               perror(ERROR_PREFIX "mq_unlink");
               return PTS_UNRESOLVED;
	}
        if (!enter_handler) {
		printf("Test PASSED \n");
		mqclean(mqdes, mqname);
		return PTS_PASS;
	}
	else {
		printf("Test FAILED \n");
		mqclean(mqdes, mqname);
		return PTS_FAIL;
	}
}
Example #3
0
int main()
{
	char mqname[NAMESIZE];
	mqd_t mqdes;
	const char s_msg_ptr[MSG_SIZE] = "test message \n";
	char r_msg_ptr[MSG_SIZE];
	struct sigevent notification;
	struct sigaction sa;
        unsigned int prio = 1;
	int pid;
	struct mq_attr attr;

	sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid());
	attr.mq_msgsize = BUFFER;
	attr.mq_maxmsg = BUFFER;

	mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr);
	if (mqdes == (mqd_t)-1) {
		perror(ERROR_PREFIX "mq_open");
		mqclean(mqdes, mqname);
		return PTS_UNRESOLVED;
	}

	pid = fork();
        if (pid == -1) {
                perror(ERROR_PREFIX "fork");
		mqclean(mqdes, mqname);
                return PTS_UNRESOLVED;
        }
        if (pid == 0) {
                /* child process */
		mq_receive(mqdes, r_msg_ptr, MSG_SIZE, NULL);
		return 0;
	}
	else {
		/* parent process */
		sleep(2); /* after 2 seconds,
			      assume that child with block on mq_receive. */
		notification.sigev_notify = SIGEV_SIGNAL;
		notification.sigev_signo = SIGUSR1;
		sa.sa_handler = msg_handler;
       	 	sa.sa_flags = 0;
        	sigaction(SIGUSR1, &sa, NULL);
		if (mq_notify(mqdes, &notification) != 0) {
			perror(ERROR_PREFIX "mq_notify");
			return PTS_UNRESOLVED;
		}
		if (mq_send(mqdes, s_msg_ptr, MSG_SIZE, prio) == -1) {
	                perror(ERROR_PREFIX "mq_send");
	                return PTS_UNRESOLVED;
	        }
		sleep(1);
		if (mq_unlink(mqname) != 0) {
	                perror(ERROR_PREFIX "mq_unlink");
	                return PTS_UNRESOLVED;
		}
		if (enter_handler) {
			printf("Test FAILED \n");
			return PTS_FAIL;
		}
		printf("Test PASSED \n");
		mqclean(mqdes, mqname);
		return PTS_PASS;
	}
}