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/01/25 07:36:15 UTC

svn commit: r1561265 - in /apr/apr/trunk: CHANGES shmem/unix/shm.c

Author: jim
Date: Sat Jan 25 06:36:15 2014
New Revision: 1561265

URL: http://svn.apache.org/r1561265
Log:
Because of Darwin/OSX, we need to worry about
the pathlength, which is much less than 255. So use
the method from posix sems, which we've used for
years!

Modified:
    apr/apr/trunk/CHANGES
    apr/apr/trunk/shmem/unix/shm.c

Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1561265&r1=1561264&r2=1561265&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Sat Jan 25 06:36:15 2014
@@ -2,7 +2,7 @@
 Changes for APR 2.0.0
 
   *) Fix POSIX shared memory (shm_open) use for named shared memory.
-     PR 55928. [Jozef Hatala <jh-asf skrt org>]
+     PR 55928. [Jozef Hatala <jh-asf skrt org>, Jim Jagielski]
 
   *) Windows platform: Remove support for Windows 9x.
 

Modified: apr/apr/trunk/shmem/unix/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/unix/shm.c?rev=1561265&r1=1561264&r2=1561265&view=diff
==============================================================================
--- apr/apr/trunk/shmem/unix/shm.c (original)
+++ apr/apr/trunk/shmem/unix/shm.c Sat Jan 25 06:36:15 2014
@@ -33,48 +33,37 @@
 #ifndef NAME_MAX
 #define NAME_MAX 255
 #endif
-static const char *make_shm_open_safe_name(const char *filename,
-                                           apr_pool_t *pool)
-{
-    const char *in;
-    char *result;
-    char *out;
-    apr_size_t len = 0;
 
-    if (filename == NULL)
-        return NULL;
-
-    len = strlen(filename);
-    if (filename[0] != '/') {
-        ++len;
-    }
-    if (len > NAME_MAX) {
-        len = NAME_MAX;
+/* See proc_mutex.c and sem_open for the reason for all this! */
+static unsigned int rshash (const char *p) {
+    /* hash function from Robert Sedgwicks 'Algorithms in C' book */
+    unsigned int b    = 378551;
+    unsigned int a    = 63689;
+    unsigned int retval = 0;
+
+    for( ; *p; p++) {
+        retval = retval * a + (*p);
+        a *= b;
     }
-    /* Allocate the required string */
-    result = apr_palloc(pool, len+1);
 
-    in = filename;
-    if (*in == '/') {
-        ++in;
-    }
+    return retval;
+}
 
-    out = result;
-    *out++ = '/';
+static const char *make_shm_open_safe_name(const char *filename,
+                                           apr_pool_t *pool)
+{
+    apr_ssize_t flen;
+    unsigned int h1, h2;
 
-    for ( ; --len; ++in, ++out) {
-        if (*in == '/') {
-            /* '/' becomes '|' */
-            *out = '|';
-        } else {
-            /* Everything else remains unchanged */
-            *out = *in;
-        }
+    if (filename == NULL) {
+        return NULL;
     }
 
-    *out = '\0';
+    flen = strlen(filename);
+    h1 = (apr_hashfunc_default(filename, &flen) & 0xffffffff);
+    h2 = (rshash(filename) & 0xffffffff);
+    return apr_psprintf(pool, "/ShM.%xH%x", h1, h2);
 
-    return result;
 }
 #endif