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:37:26 UTC

svn commit: r1561266 - in /apr/apr/branches/1.5.x: ./ CHANGES shmem/unix/shm.c

Author: jim
Date: Sat Jan 25 06:37:26 2014
New Revision: 1561266

URL: http://svn.apache.org/r1561266
Log:
Merge r1561265 from trunk:

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!

Reviewed/backported by: jim

Modified:
    apr/apr/branches/1.5.x/   (props changed)
    apr/apr/branches/1.5.x/CHANGES
    apr/apr/branches/1.5.x/shmem/unix/shm.c

Propchange: apr/apr/branches/1.5.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r1561265

Modified: apr/apr/branches/1.5.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/CHANGES?rev=1561266&r1=1561265&r2=1561266&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.5.x/CHANGES [utf-8] Sat Jan 25 06:37:26 2014
@@ -2,7 +2,7 @@
 Changes for APR 1.5.1
 
   *) 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]
 
   *) Fix race condition when calling apr_dir_make_recursive from
      multiple threads on Windows.

Modified: apr/apr/branches/1.5.x/shmem/unix/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/shmem/unix/shm.c?rev=1561266&r1=1561265&r2=1561266&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/shmem/unix/shm.c (original)
+++ apr/apr/branches/1.5.x/shmem/unix/shm.c Sat Jan 25 06:37:26 2014
@@ -32,48 +32,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