apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1561394 - in /apr/apr/trunk: CHANGES shmem/unix/shm.c
Date Sat, 25 Jan 2014 20:35:02 GMT
Author: jim
Date: Sat Jan 25 20:35:02 2014
New Revision: 1561394

URL: http://svn.apache.org/r1561394
Log:
Okey dokey... how we gen the key isn't part of our ABI,
so we can fix it without breaking it.

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=1561394&r1=1561393&r2=1561394&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Sat Jan 25 20:35:02 2014
@@ -1,6 +1,10 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) When using shmget-based shared memory, the ID used for ftok is
+     now an APR hash of the filename instead of the constant '1'.
+     We do this to help avoid collisions. PR 53996 [Jim Jagielski]
+
   *) Fix POSIX shared memory (shm_open) use for named shared memory.
      Includes adding '--enable-posix-shm' to force POSIX shm if
      available, and OSX compatibility. PR 55928.

Modified: apr/apr/trunk/shmem/unix/shm.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/shmem/unix/shm.c?rev=1561394&r1=1561393&r2=1561394&view=diff
==============================================================================
--- apr/apr/trunk/shmem/unix/shm.c (original)
+++ apr/apr/trunk/shmem/unix/shm.c Sat Jan 25 20:35:02 2014
@@ -67,6 +67,17 @@ static const char *make_shm_open_safe_na
 }
 #endif
 
+#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_)
 {
     apr_shm_t *m = (apr_shm_t *)m_;
@@ -361,7 +372,7 @@ APR_DECLARE(apr_status_t) apr_shm_create
 
         /* ftok() (on solaris at least) requires that the file actually
          * exist before calling ftok(). */
-        new_m->shmkey = ftok(filename, 1);
+        new_m->shmkey = our_ftok(filename);
         if (new_m->shmkey == (key_t)-1) {
             apr_file_close(file);
             return errno;
@@ -451,7 +462,7 @@ APR_DECLARE(apr_status_t) apr_shm_remove
 
     /* 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;
     }
@@ -623,7 +634,7 @@ APR_DECLARE(apr_status_t) apr_shm_attach
 
         new_m->filename = apr_pstrdup(pool, filename);
         new_m->pool = pool;
-        new_m->shmkey = ftok(filename, 1);
+        new_m->shmkey = our_ftok(filename);
         if (new_m->shmkey == (key_t)-1) {
             return errno;
         }



Mime
View raw message