summaryrefslogtreecommitdiffstats
path: root/cpukit/posix/src/shmunlink.c
diff options
context:
space:
mode:
authorGedare Bloom <gedare@rtems.org>2016-08-12 15:25:10 -0400
committerGedare Bloom <gedare@rtems.org>2017-01-13 11:17:30 -0500
commitba77628250ae7158db363fc0d7886ebd43e9cb69 (patch)
tree91a8a5b7d20399c69c5c88223a43ec681451996b /cpukit/posix/src/shmunlink.c
parentposix: fix typo in mmap arguments (diff)
downloadrtems-ba77628250ae7158db363fc0d7886ebd43e9cb69.tar.bz2
posix: shared memory support
Add POSIX shared memory manager (Shm). Includes a hook-based approach for the backing memory storage that defaults to the Workspace, and a test is provided using the heap. A test is also provided for the basic use of mmap'ing a shared memory object. This test currently fails at the mmap stage due to no support for mmap.
Diffstat (limited to 'cpukit/posix/src/shmunlink.c')
-rw-r--r--cpukit/posix/src/shmunlink.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/cpukit/posix/src/shmunlink.c b/cpukit/posix/src/shmunlink.c
index f5599227b1..ab18450dc7 100644
--- a/cpukit/posix/src/shmunlink.c
+++ b/cpukit/posix/src/shmunlink.c
@@ -18,9 +18,35 @@
#include <errno.h>
#include <rtems/seterr.h>
+#include <rtems/posix/shmimpl.h>
+
int shm_unlink( const char *name )
{
- (void) name;
+ Objects_Get_by_name_error obj_err;
+ int err = 0;
+ POSIX_Shm_Control *shm;
+
+ shm = _POSIX_Shm_Get_by_name( name, 0, &obj_err );
+ switch ( obj_err ) {
+ case OBJECTS_GET_BY_NAME_INVALID_NAME:
+ err = ENOENT;
+ break;
+
+ case OBJECTS_GET_BY_NAME_NAME_TOO_LONG:
+ err = ENAMETOOLONG;
+ break;
- rtems_set_errno_and_return_minus_one( ENOENT );
+ case OBJECTS_GET_BY_NAME_NO_OBJECT:
+ default:
+ _Objects_Close( &_POSIX_Shm_Information, &shm->Object );
+ if ( shm->reference_count == 0 ) {
+ /* TODO: need to make sure this counts mmaps too! */
+ /* only remove the shm object if no references exist to it. */
+ _POSIX_Shm_Free( shm );
+ }
+ break;
+ }
+ if ( err != 0 )
+ rtems_set_errno_and_return_minus_one( err );
+ return 0;
}