From d4548d19b461d2c8b896872599ae49a051622548 Mon Sep 17 00:00:00 2001 From: Jennifer Averett Date: Thu, 23 Dec 1999 22:07:11 +0000 Subject: + Made work + Added checks for valid attribute maxmsg and msgsize + Added check for ENAMETOOLONG --- cpukit/posix/src/mqueuecreatesupp.c | 70 +++++++++++++++++++++++++++++-------- 1 file changed, 55 insertions(+), 15 deletions(-) (limited to 'cpukit') diff --git a/cpukit/posix/src/mqueuecreatesupp.c b/cpukit/posix/src/mqueuecreatesupp.c index a4ce7269cb..894b11d891 100644 --- a/cpukit/posix/src/mqueuecreatesupp.c +++ b/cpukit/posix/src/mqueuecreatesupp.c @@ -37,21 +37,33 @@ int _POSIX_Message_queue_Create_support( const char *name, int pshared, unsigned int oflag, - struct mq_attr *attr, + struct mq_attr *attr_ptr, POSIX_Message_queue_Control **message_queue ) { POSIX_Message_queue_Control *the_mq; - + CORE_message_queue_Attributes *the_mq_attr; + struct mq_attr attr; + _Thread_Disable_dispatch(); - the_mq = _POSIX_Message_queue_Allocate(); - - if ( !the_mq ) { - _Thread_Enable_dispatch(); - set_errno_and_return_minus_one( ENFILE ); + if ( attr_ptr == NULL ) { + attr.mq_maxmsg = 0; /* XXX */ + attr.mq_msgsize = 0; /* XXX */ + } else { + if ( attr_ptr->mq_maxmsg < 0 ){ + _Thread_Enable_dispatch(); + set_errno_and_return_minus_one( EINVAL ); + } + + if ( attr_ptr->mq_msgsize < 0 ){ + _Thread_Enable_dispatch(); + set_errno_and_return_minus_one( EINVAL ); + } + + attr = *attr_ptr; } - + #if defined(RTEMS_MULTIPROCESSING) if ( pshared == PTHREAD_PROCESS_SHARED && !( _Objects_MP_Allocate_and_open( &_POSIX_Message_queue_Information, 0, @@ -62,16 +74,38 @@ int _POSIX_Message_queue_Create_support( } #endif + if ( name ) { + + if( strlen(name) > PATH_MAX ) { /* XXX - Is strlen ok to use here ? */ + _Thread_Enable_dispatch(); + set_errno_and_return_minus_one( ENAMETOOLONG ); + } + + /* + * XXX Greater than NAME_MAX while POSIX_NO_TRUNC in effect. + * XXX Error description in POSIX book different for mq_open and mq_unlink + * Why??? + */ + } + + the_mq = _POSIX_Message_queue_Allocate(); + if ( !the_mq ) { + _Thread_Enable_dispatch(); + set_errno_and_return_minus_one( ENFILE ); + } + the_mq->process_shared = pshared; if ( name ) { the_mq->named = TRUE; the_mq->open_count = 1; the_mq->linked = TRUE; - } - else + } + else { the_mq->named = FALSE; - + + } + if ( oflag & O_NONBLOCK ) the_mq->blocking = FALSE; else @@ -90,16 +124,18 @@ int _POSIX_Message_queue_Create_support( the_mq_attr->message_discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; the_mq_attr->waiting_discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; */ + the_mq->Message_queue.Attributes.discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; - + the_mq_attr = &the_mq->Message_queue.Attributes; + if ( ! _CORE_message_queue_Initialize( &the_mq->Message_queue, OBJECTS_POSIX_MESSAGE_QUEUES, - &the_mq->Message_queue.Attributes, - attr->mq_maxmsg, - attr->mq_msgsize, + the_mq_attr, + attr.mq_maxmsg, + attr.mq_msgsize, #if defined(RTEMS_MULTIPROCESSING) _POSIX_Message_queue_MP_Send_extract_proxy #else @@ -141,3 +177,7 @@ int _POSIX_Message_queue_Create_support( return 0; } + + + + -- cgit v1.2.3