Blob Blame History Raw

https://svn.apache.org/viewvc?view=revision&revision=1561395

--- apr-1.4.8/shmem/unix/shm.c.r1561395
+++ apr-1.4.8/shmem/unix/shm.c
@@ -20,6 +20,18 @@
 #include "apr_errno.h"
 #include "apr_user.h"
 #include "apr_strings.h"
+#include "apr_hash.h"
+
+#if APR_USE_SHMEM_SHMGET
+static key_t our_ftok(const char *filename)
+{
+    /* to help avoid collisions while still using
+     * an easily recreated proj_id */
+    apr_ssize_t slen = strlen(filename);
+    return ftok(filename,
+                (int)apr_hashfunc_default(filename, &slen));
+}
+#endif
 
 static apr_status_t shm_cleanup_owner(void *m_)
 {
@@ -312,7 +324,7 @@
 
         /* ftok() (on solaris at least) requires that the file actually
          * exist before calling ftok(). */
-        shmkey = ftok(filename, 1);
+        shmkey = our_ftok(filename);
         if (shmkey == (key_t)-1) {
             return errno;
         }
@@ -386,7 +398,7 @@
 
     /* ftok() (on solaris at least) requires that the file actually
      * exist before calling ftok(). */
-    shmkey = ftok(filename, 1);
+    shmkey = our_ftok(filename);
     if (shmkey == (key_t)-1) {
         goto shm_remove_failed;
     }
@@ -540,7 +552,7 @@
 
         new_m->filename = apr_pstrdup(pool, filename);
         new_m->pool = pool;
-        shmkey = ftok(filename, 1);
+        shmkey = our_ftok(filename);
         if (shmkey == (key_t)-1) {
             return errno;
         }