You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by ji...@apache.org on 2014/04/28 15:15:03 UTC
svn commit: r1590625 - in /apr/apr/branches/1.6.x: CHANGES include/apr_shm.h
shmem/beos/shm.c shmem/os2/shm.c shmem/unix/shm.c shmem/win32/shm.c
test/testshm.c
Author: jim
Date: Mon Apr 28 13:15:03 2014
New Revision: 1590625
URL: http://svn.apache.org/r1590625
Log:
Add apr_shm_delete()
r1590624 from trunk
Modified:
apr/apr/branches/1.6.x/CHANGES
apr/apr/branches/1.6.x/include/apr_shm.h
apr/apr/branches/1.6.x/shmem/beos/shm.c
apr/apr/branches/1.6.x/shmem/os2/shm.c
apr/apr/branches/1.6.x/shmem/unix/shm.c
apr/apr/branches/1.6.x/shmem/win32/shm.c
apr/apr/branches/1.6.x/test/testshm.c
Modified: apr/apr/branches/1.6.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/CHANGES?rev=1590625&r1=1590624&r2=1590625&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.6.x/CHANGES [utf-8] Mon Apr 28 13:15:03 2014
@@ -1,6 +1,9 @@
-*- coding: utf-8 -*-
Changes for APR 1.6.0
+ *) Add apr_shm_delete() to compliment apr_shm_remove().
+ [Jim Jagielski]
+
*) Intruduce APR_PERMS_SET macros for setting the owner/group on
objects. Currently only implemented for shm, proc and global
mutexes on posix platforms.
Modified: apr/apr/branches/1.6.x/include/apr_shm.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/include/apr_shm.h?rev=1590625&r1=1590624&r2=1590625&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/include/apr_shm.h (original)
+++ apr/apr/branches/1.6.x/include/apr_shm.h Mon Apr 28 13:15:03 2014
@@ -137,6 +137,21 @@ APR_DECLARE(apr_status_t) apr_shm_remove
apr_pool_t *pool);
/**
+ * Delete named resource associated with a shared memory segment,
+ * preventing attachments to the resource.
+ * @param m The shared memory segment structure to delete.
+ * @remark This function is only supported on platforms which support
+ * name-based shared memory segments, and will return APR_ENOTIMPL on
+ * platforms without such support. Removing the file while the shm
+ * is in use is not entirely portable, caller may use this to enhance
+ * obscurity of the resource, but be prepared for the call to fail,
+ * and for concurrent attempts to create a resource of the same name
+ * to also fail. The pool cleanup of apr_shm_create (apr_shm_destroy)
+ * also removes the named resource.
+ */
+APR_DECLARE(apr_status_t) apr_shm_delete(apr_shm_t *m);
+
+/**
* Destroy a shared memory segment and associated memory.
* @param m The shared memory segment structure to destroy.
*/
Modified: apr/apr/branches/1.6.x/shmem/beos/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/shmem/beos/shm.c?rev=1590625&r1=1590624&r2=1590625&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/shmem/beos/shm.c (original)
+++ apr/apr/branches/1.6.x/shmem/beos/shm.c Mon Apr 28 13:15:03 2014
@@ -100,6 +100,16 @@ APR_DECLARE(apr_status_t) apr_shm_remove
return APR_SUCCESS;
}
+APR_DECLARE(apr_status_t) apr_shm_delete(apr_shm_t *m)
+{
+ if (m->filename) {
+ return apr_shm_remove(m->filename, m->pool);
+ }
+ else {
+ return APR_ENOTIMPL;
+ }
+}
+
APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
const char *filename,
apr_pool_t *pool)
Modified: apr/apr/branches/1.6.x/shmem/os2/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/shmem/os2/shm.c?rev=1590625&r1=1590624&r2=1590625&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/shmem/os2/shm.c (original)
+++ apr/apr/branches/1.6.x/shmem/os2/shm.c Mon Apr 28 13:15:03 2014
@@ -77,6 +77,11 @@ APR_DECLARE(apr_status_t) apr_shm_remove
return APR_ENOTIMPL;
}
+APR_DECLARE(apr_status_t) apr_shm_delete(apr_shm_t *m)
+{
+ return APR_ENOTIMPL;
+}
+
APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
const char *filename,
apr_pool_t *pool)
Modified: apr/apr/branches/1.6.x/shmem/unix/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/shmem/unix/shm.c?rev=1590625&r1=1590624&r2=1590625&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/shmem/unix/shm.c (original)
+++ apr/apr/branches/1.6.x/shmem/unix/shm.c Mon Apr 28 13:15:03 2014
@@ -491,6 +491,16 @@ shm_remove_failed:
#endif
}
+APR_DECLARE(apr_status_t) apr_shm_delete(apr_shm_t *m)
+{
+ if (m->filename) {
+ return apr_shm_remove(m->filename, m->pool);
+ }
+ else {
+ return APR_ENOTIMPL;
+ }
+}
+
APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m)
{
return apr_pool_cleanup_run(m->pool, m, shm_cleanup_owner);
Modified: apr/apr/branches/1.6.x/shmem/win32/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/shmem/win32/shm.c?rev=1590625&r1=1590624&r2=1590625&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/shmem/win32/shm.c (original)
+++ apr/apr/branches/1.6.x/shmem/win32/shm.c Mon Apr 28 13:15:03 2014
@@ -261,6 +261,16 @@ APR_DECLARE(apr_status_t) apr_shm_remove
return apr_file_remove(filename, pool);
}
+APR_DECLARE(apr_status_t) apr_shm_delete(apr_shm_t *m)
+{
+ if (m->filename) {
+ return apr_shm_remove(m->filename, m->pool);
+ }
+ else {
+ return APR_ENOTIMPL;
+ }
+}
+
static apr_status_t shm_attach_internal(apr_shm_t **m,
const char *file,
apr_pool_t *pool,
Modified: apr/apr/branches/1.6.x/test/testshm.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/test/testshm.c?rev=1590625&r1=1590624&r2=1590625&view=diff
==============================================================================
--- apr/apr/branches/1.6.x/test/testshm.c (original)
+++ apr/apr/branches/1.6.x/test/testshm.c Mon Apr 28 13:15:03 2014
@@ -268,6 +268,46 @@ static void test_named_remove(abts_case
ABTS_TRUE(tc, rv != 0);
}
+static void test_named_delete(abts_case *tc, void *data)
+{
+ apr_status_t rv;
+ apr_shm_t *shm, *shm2;
+
+ apr_shm_remove(SHARED_FILENAME, p);
+
+ rv = apr_shm_create(&shm, SHARED_SIZE, SHARED_FILENAME, p);
+ APR_ASSERT_SUCCESS(tc, "Error allocating shared memory block", rv);
+ if (rv != APR_SUCCESS) {
+ return;
+ }
+ ABTS_PTR_NOTNULL(tc, shm);
+
+ rv = apr_shm_delete(shm);
+
+ /* On platforms which acknowledge the removal of the shared resource,
+ * ensure another of the same name may be created after removal;
+ */
+ if (rv == APR_SUCCESS)
+ {
+ rv = apr_shm_create(&shm2, SHARED_SIZE, SHARED_FILENAME, p);
+ APR_ASSERT_SUCCESS(tc, "Error allocating shared memory block", rv);
+ if (rv != APR_SUCCESS) {
+ return;
+ }
+ ABTS_PTR_NOTNULL(tc, shm2);
+
+ rv = apr_shm_destroy(shm2);
+ APR_ASSERT_SUCCESS(tc, "Error destroying shared memory block", rv);
+ }
+
+ rv = apr_shm_destroy(shm);
+ APR_ASSERT_SUCCESS(tc, "Error destroying shared memory block", rv);
+
+ /* Now ensure no named resource remains which we may attach to */
+ rv = apr_shm_attach(&shm, SHARED_FILENAME, p);
+ ABTS_TRUE(tc, rv != 0);
+}
+
#endif
abts_suite *testshm(abts_suite *suite)
@@ -283,6 +323,7 @@ abts_suite *testshm(abts_suite *suite)
#endif
abts_run_test(suite, test_named, NULL);
abts_run_test(suite, test_named_remove, NULL);
+ abts_run_test(suite, test_named_delete, NULL);
#endif
return suite;