Are POSIX mqueues supposed to be functional on FreeBSD?

Garrett Cooper yanefbsd at gmail.com
Sun Jun 20 22:02:36 UTC 2010


    Err... I ran an mqueue test and it popped up with ENOSYS. Which
makes me wonder, are POSIX mqueues implemented 100% on FreeBSD? I
looked into sys/kern/uip_mqueue.c and it _appears_ functional, but I
could be misreading the code. Another test written which tests mqueue
appears to be broken as well (I'll include that in a later email if
interested). I also attached the truss output and the relative code
blurb for a little more analysis.
Thanks,
-Garrett

PS I'm not guaranteeing that the code below doesn't have bugs in it as
I'm not the original author and the tests were originally written and
targeted towards Linux.

$ uname -a
FreeBSD bayonetta.local 9.0-CURRENT FreeBSD 9.0-CURRENT #0 r206173M:
Mon Apr 26 22:45:06 PDT 2010
root at bayonetta.local:/usr/obj/usr/src/sys/BAYONETTA.ata  amd64
$ truss functional/mqueues/send_rev_2.test
__sysctl(0x7fffffffe130,0x2,0x7fffffffe14c,0x7fffffffe140,0x0,0x0) = 0 (0x0)
mmap(0x0,672,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 34365173760 (0x80052f000)
munmap(0x80052f000,672)                          = 0 (0x0)
__sysctl(0x7fffffffe1a0,0x2,0x800639848,0x7fffffffe198,0x0,0x0) = 0 (0x0)
mmap(0x0,32768,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) =
34365173760 (0x80052f000)
issetugid(0x800530015,0x80052a524,0x800645f50,0x800645f20,0x5af1,0x0) = 0 (0x0)
open("/etc/libmap.conf",O_RDONLY,0666)           ERR#2 'No such file
or directory'
open("/var/run/ld-elf.so.hints",O_RDONLY,057)    = 2 (0x2)
read(2,"Ehnt\^A\0\0\0\M^@\0\0\0j\0\0\0\0"...,128) = 128 (0x80)
lseek(2,0x80,SEEK_SET)                           = 128 (0x80)
read(2,"/lib:/usr/lib:/usr/lib/compat:/u"...,106) = 106 (0x6a)
close(2)                                         = 0 (0x0)
access("/lib/libthr.so.3",0)                     = 0 (0x0)
open("/lib/libthr.so.3",O_RDONLY,030713440)      = 2 (0x2)
fstat(2,{ mode=-r--r--r-- ,inode=400430,size=85264,blksize=16384 }) = 0 (0x0)
pread(0x2,0x800638700,0x1000,0x0,0x101010101010101,0x8080808080808080)
= 4096 (0x1000)
mmap(0x0,1142784,PROT_NONE,MAP_PRIVATE|MAP_ANON|MAP_NOCORE,-1,0x0) =
34366316544 (0x800646000)
mmap(0x800646000,73728,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE,2,0x0)
= 34366316544 (0x800646000)
mmap(0x800757000,12288,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,2,0x11000)
= 34367434752 (0x800757000)
mprotect(0x80075a000,12288,PROT_READ|PROT_WRITE) = 0 (0x0)
close(2)                                         = 0 (0x0)
access("/lib/librt.so.1",0)                      ERR#2 'No such file
or directory'
access("/usr/lib/librt.so.1",0)                  = 0 (0x0)
open("/usr/lib/librt.so.1",O_RDONLY,030713440)   = 2 (0x2)
fstat(2,{ mode=-r--r--r-- ,inode=2567883,size=21424,blksize=16384 }) = 0 (0x0)
pread(0x2,0x800638700,0x1000,0x0,0x101010101010101,0x8080808080808080)
= 4096 (0x1000)
mmap(0x0,1069056,PROT_NONE,MAP_PRIVATE|MAP_ANON|MAP_NOCORE,-1,0x0) =
34367459328 (0x80075d000)
mmap(0x80075d000,20480,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE,2,0x0)
= 34367459328 (0x80075d000)
mmap(0x800861000,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,2,0x4000)
= 34368524288 (0x800861000)
close(2)                                         = 0 (0x0)
access("/lib/libc.so.7",0)                       = 0 (0x0)
open("/lib/libc.so.7",O_RDONLY,030713440)        = 2 (0x2)
fstat(2,{ mode=-r--r--r-- ,inode=400388,size=1156744,blksize=16384 }) = 0 (0x0)
pread(0x2,0x800638700,0x1000,0x0,0x101010101010101,0x8080808080808080)
= 4096 (0x1000)
mmap(0x0,2281472,PROT_NONE,MAP_PRIVATE|MAP_ANON|MAP_NOCORE,-1,0x0) =
34368528384 (0x800862000)
mmap(0x800862000,995328,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_FIXED|MAP_NOCORE,2,0x0)
= 34368528384 (0x800862000)
mmap(0x800a54000,131072,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_FIXED,2,0xf2000)
= 34370568192 (0x800a54000)
mprotect(0x800a74000,110592,PROT_READ|PROT_WRITE) = 0 (0x0)
close(2)                                         = 0 (0x0)
sysarch(0x81,0x7fffffffe220,0x800534188,0x0,0xffffffffffad9550,0x8080808080808080)
= 0 (0x0)
mmap(0x0,416,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 34365206528 (0x800537000)
munmap(0x800537000,416)                          = 0 (0x0)
mmap(0x0,8064,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 34365206528 (0x800537000)
munmap(0x800537000,8064)                         = 0 (0x0)
mmap(0x0,2944,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 34365206528 (0x800537000)
munmap(0x800537000,2944)                         = 0 (0x0)
mmap(0x0,43296,PROT_READ|PROT_WRITE,MAP_ANON,-1,0x0) = 34365206528 (0x800537000)
munmap(0x800537000,43296)                        = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0)
= 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
__sysctl(0x7fffffffe1c0,0x2,0x800a7ab40,0x7fffffffe1b8,0x0,0x0) = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0)
= 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
getpid()                                         = 45130 (0xb04a)
__sysctl(0x7fffffffe1b0,0x2,0x80075c3f0,0x7fffffffe1b8,0x0,0x0) = 0 (0x0)
__sysctl(0x7fffffffe0d0,0x2,0x7fffffffe0f0,0x7fffffffe158,0x800656dc8,0xd)
= 0 (0x0)
__sysctl(0x7fffffffe0f0,0x3,0x80075b2e8,0x7fffffffe1b8,0x0,0x0) = 0 (0x0)
__sysctl(0x7fffffffe170,0x2,0x800a7a628,0x7fffffffe168,0x0,0x0) = 0 (0x0)
__sysctl(0x7fffffffdc60,0x2,0x7fffffffdc8c,0x7fffffffdc80,0x0,0x0) = 0 (0x0)
__sysctl(0x7fffffffdb50,0x2,0x7fffffffdb70,0x7fffffffdbd8,0x80094d340,0xc)
= 0 (0x0)
__sysctl(0x7fffffffdb70,0x2,0x800a7a2f0,0x7fffffffdc20,0x0,0x0) = 0 (0x0)
readlink("/etc/malloc.conf",0x7fffffffdc90,1024) ERR#2 'No such file
or directory'
issetugid(0x80094bf4f,0x7fffffffdc90,0x0,0x0,0x2,0x0) = 0 (0x0)
break(0x800000)                                  = 0 (0x0)
__sysctl(0x7fffffffdcb0,0x2,0x7fffffffdccc,0x7fffffffdcc0,0x0,0x0) = 0 (0x0)
mmap(0x0,4194304,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) =
34370809856 (0x800a8f000)
mmap(0x800e8f000,1511424,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0)
= 34375004160 (0x800e8f000)
munmap(0x800a8f000,1511424)                      = 0 (0x0)
thr_self(0x800c071c0,0x0,0x0,0x0,0x188,0x5018a8) = 0 (0x0)
mmap(0x7fffffbff000,4096,PROT_NONE,MAP_ANON,-1,0x0) = 140737484156928
(0x7fffffbff000)
thr_set_name(0x18a7f,0x800656e10,0x0,0x1000,0xffffffff,0x0) = 0 (0x0)
rtprio_thread(0x0,0x18a7f,0x7fffffffe160,0x1000,0xffffffff,0x0) = 0 (0x0)
sysarch(0x81,0x7fffffffe180,0x80075aec0,0x80075b248,0xffffffff,0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,SIGHUP|SIGINT|SIGQUIT|SIGILL|SIGABRT|SIGEMT|SIGFPE|SIGKILL|SIGBUS|SIGSEGV|SIGSYS|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0)
= 0 (0x0)
sigaction(32,{ 0x8006511dc SA_RESTART|SA_SIGINFO ss_t },0x0) = 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0)
= 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
sigprocmask(SIG_BLOCK,SIGHUP|SIGINT|SIGQUIT|SIGKILL|SIGPIPE|SIGALRM|SIGTERM|SIGURG|SIGSTOP|SIGTSTP|SIGCONT|SIGCHLD|SIGTTIN|SIGTTOU|SIGIO|SIGXCPU|SIGXFSZ|SIGVTALRM|SIGPROF|SIGWINCH|SIGINFO|SIGUSR1|SIGUSR2,0x0)
= 0 (0x0)
sigprocmask(SIG_SETMASK,0x0,0x0)                 = 0 (0x0)
kmq_open(0x401089,0x206,0x1ff,0x7fffffffe6a0,0x10,0x5018a8) ERR#78
'Function not implemented'
SIGNAL 12 (SIGSYS)
process exit, rval = 0

/*
 * Copyright (c) 2002, Intel Corporation. All rights reserved.
 * Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
 * This file is licensed under the GPL license.  For the full content
 * of this license, see the COPYING file at the top level of this
 * source tree.
 *
 * 1. Two threads sending/receiving on different message queue.
 * 2. Set different Priority to the messages in the message queue, to
 * see whether the highest priority is received first.
 */

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <string.h>
#include <getopt.h>
#include <pthread.h>
#include <limits.h>
#include <mqueue.h>

#include "posixtest.h"

#define MQ_NAME_1       "/testmsg1"
#define MQ_NAME_2       "/testmsg2"
#define MSG_SIZE	128
#define MAX_MSG		3

const char *s_msg_ptr[] = {"msg test 1", "msg test 2", "msg test 3"};
char r_msg_ptr_1[MAX_MSG][MSG_SIZE];
char r_msg_ptr_2[MAX_MSG][MSG_SIZE];
pthread_t send1, send2, rev1, rev2;

int * send_1(void * mq)
{
	int i;
	mqd_t mq1 = *(mqd_t *)mq;

	printf("Enter into send_1 \n");
	for (i = 0; i < MAX_MSG; i++ ) {
		if ( -1 == mq_send(mq1, s_msg_ptr[i], MSG_SIZE, i)) {
			perror("mq_send doesn't return success \n");
			pthread_exit((void *)1);
		}
		printf("[%d] send '%s' in thread send_1. \n", i+1, s_msg_ptr[i]);
	}
	pthread_exit((void *)0);

}
int * send_2(void * mq)
{
	int i;
 	mqd_t mq2 = *(mqd_t *)mq;

	printf("Enter into send_2 \n");
	for (i = 0; i < MAX_MSG; i++ ) {
		if ( -1 == mq_send(mq2, s_msg_ptr[i], MSG_SIZE, i)) {
			perror("mq_send doesn't return success \n");
			pthread_exit((void *)1);
		}
		printf("[%d] send '%s' in thread send_2. \n", i+1, s_msg_ptr[i]);
	}
	pthread_exit((void *)0);
}
int * receive_1(void * mq)
{
	int i;
	mqd_t mq1 = *(mqd_t *)mq;

	printf("Enter into receive_1 \n");
	for (i = 0; i< MAX_MSG; i++) {
		if ( -1 == mq_receive(mq1, r_msg_ptr_1[i], MSG_SIZE, NULL) ) {
			perror("mq_receive doesn't return success \n");
			pthread_exit((void *)1);
		}
		printf("[%d] receive '%s' in thread receive_1. \n", i+1, r_msg_ptr_1[i]);
	}
	pthread_exit((void *)0);
}
int * receive_2(void * mq)
{
	int i;
	mqd_t mq2 = *(mqd_t *)mq;

	printf("Enter into receive_2 \n");
	for (i = 0; i< MAX_MSG; i++) {
		if ( -1 == mq_receive(mq2, r_msg_ptr_2[i], MSG_SIZE, NULL) ) {
			perror("mq_receive doesn't return success \n");
			pthread_exit((void *)1);
		}
		printf("[%d] receive '%s' in thread receive_2. \n", i+1, r_msg_ptr_2[i]);
	}
	pthread_exit((void *)0);
}
int main(int argc, char *argv[])
{
	
 	mqd_t mq1 = 0, mq2 = 0;	
	struct mq_attr mqstat;
	int oflag = O_CREAT|O_NONBLOCK|O_RDWR;

	memset(&mqstat, 0, sizeof(mqstat));
	mqstat.mq_maxmsg = MAX_MSG;
	mqstat.mq_msgsize = MSG_SIZE;
	mqstat.mq_flags = 0;

  	if( ((mqd_t) -1) == (mq1 = mq_open(MQ_NAME_1,oflag,0777, &mqstat)) ) {
		printf("mq_open doesn't return success \n");
		return PTS_UNRESOLVED;
	}
  	if( ((mqd_t) -1) == (mq2 = mq_open(MQ_NAME_2,oflag,0777, &mqstat)) ) {
		printf("mq_open doesn't return success \n");
		return PTS_UNRESOLVED;
	}
	pthread_create(&send1, NULL, (void *)send_1, (void *)&mq1);
	pthread_create(&send2, NULL, (void *)send_2, (void *)&mq2);
        pthread_create(&rev1, NULL, (void *)receive_1, (void *)&mq1);	
        pthread_create(&rev2, NULL, (void *)receive_2, (void *)&mq2);	
	pthread_join(send1, NULL);
	pthread_join(send2, NULL);
	pthread_join(rev1, NULL);
	pthread_join(rev2, NULL);
		
	mq_close(mq1);
	mq_close(mq2);
	mq_unlink(MQ_NAME_1);
	mq_unlink(MQ_NAME_2);
	return PTS_PASS;
}


More information about the freebsd-standards mailing list