From 7fbef7863951899f518b70548f508ad618f9ebbd Mon Sep 17 00:00:00 2001 From: Jennifer Averett Date: Thu, 23 Dec 1999 22:09:36 +0000 Subject: + Debugged. --- cpukit/posix/src/mqueueopen.c | 47 +++++++++++++++++++++++------------ cpukit/posix/src/mqueueunlink.c | 54 +++++++++++++++++++++++------------------ 2 files changed, 61 insertions(+), 40 deletions(-) (limited to 'cpukit/posix/src') diff --git a/cpukit/posix/src/mqueueopen.c b/cpukit/posix/src/mqueueopen.c index 4ea5a63b78..911c74bc2c 100644 --- a/cpukit/posix/src/mqueueopen.c +++ b/cpukit/posix/src/mqueueopen.c @@ -47,7 +47,10 @@ mqd_t mq_open( int status; Objects_Id the_mq_id; POSIX_Message_queue_Control *the_mq; + Objects_Locations location; + _Thread_Disable_dispatch(); + if ( oflag & O_CREAT ) { va_start(arg, oflag); mode = (mode_t) va_arg( arg, mode_t ); @@ -66,31 +69,37 @@ mqd_t mq_open( if ( status ) { - if ( status == EINVAL ) { /* name -> ID translation failed */ - if ( !(oflag & O_CREAT) ) { /* willing to create it? */ - set_errno_and_return_minus_one( ENOENT ); - return (mqd_t) -1; - } - /* we are willing to create it */ + /* + * Unless provided a valid name that did not already exist + * and we are willing to create then it is an error. + */ + + if ( !( status == ENOENT && (oflag & O_CREAT) ) ) { + _Thread_Enable_dispatch(); + set_errno_and_return_minus_one_cast( status, mqd_t ); } - set_errno_and_return_minus_one( status ); /* some type of error */ - return (mqd_t) -1; - + } else { /* name -> ID translation succeeded */ + /* + * Check for existence with creation. + */ + if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) { - set_errno_and_return_minus_one( EEXIST ); - return (mqd_t) -1; + _Thread_Enable_dispatch(); + set_errno_and_return_minus_one_cast( EEXIST, mqd_t ); } - + /* * XXX In this case we need to do an ID->pointer conversion to * check the mode. This is probably a good place for a subroutine. */ - + + the_mq = _POSIX_Message_queue_Get( the_mq_id, &location ); the_mq->open_count += 1; - - return (mqd_t)&the_mq->Object.id; + _Thread_Enable_dispatch(); + _Thread_Enable_dispatch(); + return (mqd_t)the_mq->Object.id; } @@ -108,9 +117,15 @@ mqd_t mq_open( &the_mq ); + /* + * errno was set by Create_support, so don't set it again. + */ + + _Thread_Enable_dispatch(); + if ( status == -1 ) return (mqd_t) -1; - return (mqd_t) &the_mq->Object.id; + return (mqd_t) the_mq->Object.id; } diff --git a/cpukit/posix/src/mqueueunlink.c b/cpukit/posix/src/mqueueunlink.c index 421b91543c..6628e09542 100644 --- a/cpukit/posix/src/mqueueunlink.c +++ b/cpukit/posix/src/mqueueunlink.c @@ -42,34 +42,40 @@ int mq_unlink( Objects_Id the_mq_id; Objects_Locations location; + _Thread_Disable_dispatch(); + status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id ); - if ( status != 0 ) + if ( status != 0 ) { + _Thread_Enable_dispatch(); set_errno_and_return_minus_one( status ); - - the_mq = _POSIX_Message_queue_Get( the_mq_id, &location ); - switch ( location ) { - case OBJECTS_ERROR: - set_errno_and_return_minus_one( EINVAL ); - case OBJECTS_REMOTE: - _Thread_Dispatch(); - return POSIX_MP_NOT_IMPLEMENTED(); - set_errno_and_return_minus_one( EINVAL ); - case OBJECTS_LOCAL: - + } + + /* + * Don't support unlinking a remote message queue. + */ + + if ( !_Objects_Is_local_id(the_mq_id) ) { + _Thread_Enable_dispatch(); + set_errno_and_return_minus_one( ENOSYS ); + } + + the_mq = (POSIX_Message_queue_Control *) _Objects_Get_local_object( + &_POSIX_Message_queue_Information, + _Objects_Get_index( the_mq_id ) + ); + #if defined(RTEMS_MULTIPROCESSING) - _Objects_MP_Close( - &_POSIX_Message_queue_Information, - the_mq->Object.id - ); + if ( the_mq->process_shared == PTHREAD_PROCESS_SHARED ) { + _Objects_MP_Close( &_POSIX_Message_queue_Information, the_mq_id ); + } #endif + - the_mq->linked = FALSE; - - _POSIX_Message_queue_Delete( the_mq ); - - _Thread_Enable_dispatch(); - return 0; - } - return POSIX_BOTTOM_REACHED(); + the_mq->linked = FALSE; + _POSIX_Message_queue_Namespace_remove( the_mq ); + _POSIX_Message_queue_Delete( the_mq ); + + _Thread_Enable_dispatch(); + return 0; } -- cgit v1.2.3