apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r592258 - in /apr/apr/trunk: include/apr_shm.h test/testshm.c
Date Tue, 06 Nov 2007 03:58:24 GMT
Author: wrowe
Date: Mon Nov  5 19:58:22 2007
New Revision: 592258

URL: http://svn.apache.org/viewvc?rev=592258&view=rev
Log:
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.

Modified:
    apr/apr/trunk/include/apr_shm.h
    apr/apr/trunk/test/testshm.c

Modified: apr/apr/trunk/include/apr_shm.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_shm.h?rev=592258&r1=592257&r2=592258&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_shm.h (original)
+++ apr/apr/trunk/include/apr_shm.h Mon Nov  5 19:58:22 2007
@@ -71,14 +71,19 @@
                                          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);

Modified: apr/apr/trunk/test/testshm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testshm.c?rev=592258&r1=592257&r2=592258&view=diff
==============================================================================
--- apr/apr/trunk/test/testshm.c (original)
+++ apr/apr/trunk/test/testshm.c Mon Nov  5 19:58:22 2007
@@ -221,7 +221,7 @@
 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 @@
     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



Mime
View raw message