diff options
author | William A. Rowe Jr <wrowe@apache.org> | 2007-11-06 03:59:09 +0000 |
---|---|---|
committer | William A. Rowe Jr <wrowe@apache.org> | 2007-11-06 03:59:09 +0000 |
commit | bdf6a00702a6c492f5093f4ca21377b00e4da8ac (patch) | |
tree | 849ea408fa20811ac1b12e101c4adfd17ba5bc0e | |
parent | 5d973e372acfd78a4e32bfa67a4154d47d6d51ce (diff) | |
download | apr-bdf6a00702a6c492f5093f4ca21377b00e4da8ac.tar.gz |
More effectively explain apr_shm_remove, and the hints that
it provides to the caller. Document these assumptions by
way of a proper test case, cleaning up irrespective of which
implementation is available on this platform.
Backport: r592258
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.2.x@592259 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | include/apr_shm.h | 9 | ||||
-rw-r--r-- | test/testshm.c | 29 |
2 files changed, 26 insertions, 12 deletions
diff --git a/include/apr_shm.h b/include/apr_shm.h index 651d9dbbf..2b1d50f6d 100644 --- a/include/apr_shm.h +++ b/include/apr_shm.h @@ -71,14 +71,19 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, apr_pool_t *pool); /** - * Remove file associated with a shared memory segment. + * Remove named resource associated with a shared memory segment, + * preventing attachments to the resource, but not destroying it. * @param filename The filename associated with shared-memory segment which * needs to be removed * @param pool The pool used for file operations * @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 (prior to apr_shm_destroy) is non-portable. + * is in use is not entirely portable, caller may use this to enhance + * obscurity of the resource, but be prepared for the 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_remove(const char *filename, apr_pool_t *pool); diff --git a/test/testshm.c b/test/testshm.c index c660abf88..ab9b76c21 100644 --- a/test/testshm.c +++ b/test/testshm.c @@ -221,7 +221,7 @@ static void test_named(abts_case *tc, void *data) static void test_named_remove(abts_case *tc, void *data) { apr_status_t rv; - apr_shm_t *shm; + apr_shm_t *shm, *shm2; apr_shm_remove(SHARED_FILENAME, p); @@ -233,20 +233,29 @@ static void test_named_remove(abts_case *tc, void *data) ABTS_PTR_NOTNULL(tc, shm); rv = apr_shm_remove(SHARED_FILENAME, p); - APR_ASSERT_SUCCESS(tc, "Error removing shared memory block", rv); - if (rv != APR_SUCCESS) { - return ; - } - 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; + /* 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); } - ABTS_PTR_NOTNULL(tc, shm); 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 |