apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1561395 - in /apr/apr/branches/1.5.x: ./ CHANGES shmem/unix/shm.c
Date Sat, 25 Jan 2014 20:40:27 GMT
Author: jim
Date: Sat Jan 25 20:40:27 2014
New Revision: 1561395

URL: http://svn.apache.org/r1561395
Log:
Merge r1561394 from trunk:

Okey dokey... how we gen the key isn't part of our ABI,
so we can fix it without breaking it.

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:r1561394

Modified: apr/apr/branches/1.5.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.5.x/CHANGES?rev=1561395&r1=1561394&r2=1561395&view=diff
==============================================================================
--- apr/apr/branches/1.5.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.5.x/CHANGES [utf-8] Sat Jan 25 20:40:27 2014
@@ -1,6 +1,10 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 1.5.1
 
+  *) 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/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=1561395&r1=1561394&r2=1561395&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 20:40:27 2014
@@ -66,6 +66,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(). */
-        shmkey = ftok(filename, 1);
+        shmkey = our_ftok(filename);
         if (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;
     }
@@ -624,7 +635,7 @@ APR_DECLARE(apr_status_t) apr_shm_attach
 
         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;
         }



Mime
View raw message