From 17879f4750a2bc0d556c8cd1d0f6715b127d681a Mon Sep 17 00:00:00 2001 From: Jennifer Averett Date: Thu, 18 Nov 1999 19:43:13 +0000 Subject: + Debuged to the point that you could open, unlink and close a semaphore. but all paths have not been checked, yet. --- c/src/exec/posix/src/mqueueunlink.c | 3 +-- c/src/exec/posix/src/semaphorenametoid.c | 15 ++++++------- c/src/exec/posix/src/semopen.c | 36 ++++++++++++++++---------------- c/src/exec/posix/src/semunlink.c | 5 ++--- 4 files changed, 29 insertions(+), 30 deletions(-) (limited to 'c/src/exec') diff --git a/c/src/exec/posix/src/mqueueunlink.c b/c/src/exec/posix/src/mqueueunlink.c index 4a884f7b82..421b91543c 100644 --- a/c/src/exec/posix/src/mqueueunlink.c +++ b/c/src/exec/posix/src/mqueueunlink.c @@ -43,8 +43,7 @@ int mq_unlink( Objects_Locations location; status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id ); - - if ( !status ) + if ( status != 0 ) set_errno_and_return_minus_one( status ); the_mq = _POSIX_Message_queue_Get( the_mq_id, &location ); diff --git a/c/src/exec/posix/src/semaphorenametoid.c b/c/src/exec/posix/src/semaphorenametoid.c index 8761f79f8b..c6de93c201 100644 --- a/c/src/exec/posix/src/semaphorenametoid.c +++ b/c/src/exec/posix/src/semaphorenametoid.c @@ -20,7 +20,8 @@ * * _POSIX_Semaphore_Name_to_id * - * XXX + * Look up the specified name and attempt to locate the id + * for the associated semaphore. */ int _POSIX_Semaphore_Name_to_id( @@ -30,12 +31,12 @@ int _POSIX_Semaphore_Name_to_id( { Objects_Name_to_id_errors status; - status = _Objects_Name_to_id( &_POSIX_Semaphore_Information, (char *)name, 0, id ); + status = _Objects_Name_to_id( + &_POSIX_Semaphore_Information, (char *)name, 0, id ); - if ( status == OBJECTS_SUCCESSFUL ) { - return 0; - } else { - return EINVAL; - } + if ( status == OBJECTS_SUCCESSFUL ) + return 0; + + return EINVAL; } diff --git a/c/src/exec/posix/src/semopen.c b/c/src/exec/posix/src/semopen.c index c0ac7ffe3b..b52c436e74 100644 --- a/c/src/exec/posix/src/semopen.c +++ b/c/src/exec/posix/src/semopen.c @@ -43,9 +43,7 @@ sem_t *sem_open( if ( oflag & O_CREAT ) { va_start(arg, oflag); - /*mode = (mode_t) va_arg( arg, mode_t * );*/ mode = va_arg( arg, mode_t ); - /*value = (unsigned int) va_arg( arg, unsigned int * );*/ value = va_arg( arg, unsigned int ); va_end(arg); } @@ -61,35 +59,34 @@ sem_t *sem_open( if ( status ) { - if ( status == EINVAL ) { /* name -> ID translation failed */ - if ( !(oflag & O_CREAT) ) { /* willing to create it? */ + /* + * Unless we are willing to create name -> ID translation failure is + * an error. + */ + + if ( status == EINVAL ) { + if ( !(oflag & O_CREAT) ) { set_errno_and_return_minus_one_cast( ENOENT, sem_t * ); } - /* we are willing to create it */ } - /* some type of error */ - /*set_errno_and_return_minus_one_cast( status, sem_t * );*/ - } else { /* name -> ID translation succeeded */ + } else { + + /* + * Check for existence with creation. + */ if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) { set_errno_and_return_minus_one_cast( EEXIST, sem_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_semaphore = _POSIX_Semaphore_Get( &the_semaphore_id, &location ); the_semaphore->open_count += 1; - return (sem_t *)&the_semaphore->Object.id; } - /* XXX verify this comment... - * + /* * At this point, the semaphore does not exist and everything has been * checked. We should go ahead and create a semaphore. */ @@ -101,9 +98,12 @@ sem_t *sem_open( &the_semaphore ); + /* + * errno was set by Create_support, so don't set it again. + */ + if ( status == -1 ) - return (sem_t *) -1; + return SEM_FAILED; return (sem_t *) &the_semaphore->Object.id; - } diff --git a/c/src/exec/posix/src/semunlink.c b/c/src/exec/posix/src/semunlink.c index 7fc2c56a28..105a710c47 100644 --- a/c/src/exec/posix/src/semunlink.c +++ b/c/src/exec/posix/src/semunlink.c @@ -31,8 +31,7 @@ int sem_unlink( Objects_Locations location; status = _POSIX_Semaphore_Name_to_id( name, &the_semaphore_id ); - - if ( !status ) + if ( status != 0 ) set_errno_and_return_minus_one( status ); the_semaphore = _POSIX_Semaphore_Get( &the_semaphore_id, &location ); @@ -55,7 +54,7 @@ int sem_unlink( #endif the_semaphore->linked = FALSE; - + _POSIX_Semaphore_Namespace_remove( the_semaphore ); _POSIX_Semaphore_Delete( the_semaphore ); _Thread_Enable_dispatch(); -- cgit v1.2.3