apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1590624 - in /apr/apr/trunk: CHANGES include/apr_shm.h shmem/beos/shm.c shmem/os2/shm.c shmem/unix/shm.c shmem/win32/shm.c test/testshm.c
Date Mon, 28 Apr 2014 13:14:46 GMT
Author: jim
Date: Mon Apr 28 13:14:45 2014
New Revision: 1590624

URL: http://svn.apache.org/r1590624
Log:
Add apr_shm_delete()

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/include/apr_shm.h
    apr/apr/trunk/shmem/beos/shm.c
    apr/apr/trunk/shmem/os2/shm.c
    apr/apr/trunk/shmem/unix/shm.c
    apr/apr/trunk/shmem/win32/shm.c
    apr/apr/trunk/test/testshm.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1590624&r1=1590623&r2=1590624&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Mon Apr 28 13:14:45 2014
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) Add apr_shm_delete() to compliment apr_shm_remove().
+     [Jim Jagielski]
+
   *) Add apr_escape_ldap() and apr_pescape_ldap(), escaping characters
      as described by RFC4514 and RFC4515 respectively. [Graham Leggett]
 
@@ -68,6 +71,11 @@ Changes for APR 2.0.0
 
   *) Merge APR-util into APR.  [various]
 
+Changes for APR and APR-util 1.6.x and later:
+
+  *) http://svn.apache.org/viewvc/apr/apr/branches/1.6.x/CHANGES?view=markup
+  *) http://svn.apache.org/viewvc/apr/apr-util/branches/1.6.x/CHANGES?view=markup
+
 Changes for APR and APR-util 1.5.x and later:
 
   *) http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/CHANGES?view=markup

Modified: apr/apr/trunk/include/apr_shm.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_shm.h?rev=1590624&r1=1590623&r2=1590624&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_shm.h (original)
+++ apr/apr/trunk/include/apr_shm.h Mon Apr 28 13:14:45 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/trunk/shmem/beos/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/beos/shm.c?rev=1590624&r1=1590623&r2=1590624&view=diff
==============================================================================
--- apr/apr/trunk/shmem/beos/shm.c (original)
+++ apr/apr/trunk/shmem/beos/shm.c Mon Apr 28 13:14:45 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/trunk/shmem/os2/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/os2/shm.c?rev=1590624&r1=1590623&r2=1590624&view=diff
==============================================================================
--- apr/apr/trunk/shmem/os2/shm.c (original)
+++ apr/apr/trunk/shmem/os2/shm.c Mon Apr 28 13:14:45 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/trunk/shmem/unix/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/unix/shm.c?rev=1590624&r1=1590623&r2=1590624&view=diff
==============================================================================
--- apr/apr/trunk/shmem/unix/shm.c (original)
+++ apr/apr/trunk/shmem/unix/shm.c Mon Apr 28 13:14:45 2014
@@ -492,6 +492,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/trunk/shmem/win32/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/win32/shm.c?rev=1590624&r1=1590623&r2=1590624&view=diff
==============================================================================
--- apr/apr/trunk/shmem/win32/shm.c (original)
+++ apr/apr/trunk/shmem/win32/shm.c Mon Apr 28 13:14:45 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/trunk/test/testshm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testshm.c?rev=1590624&r1=1590623&r2=1590624&view=diff
==============================================================================
--- apr/apr/trunk/test/testshm.c (original)
+++ apr/apr/trunk/test/testshm.c Mon Apr 28 13:14:45 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;



Mime
View raw message