summaryrefslogtreecommitdiff
path: root/shmem
diff options
context:
space:
mode:
authorJim Jagielski <jim@apache.org>2014-01-25 06:36:15 +0000
committerJim Jagielski <jim@apache.org>2014-01-25 06:36:15 +0000
commit0f63af2a885695fc864551282d15957bed69099f (patch)
tree5ae769ce612946de72c164080c21cb6acfaf46b3 /shmem
parent65d7750a86230137e7776da2caaeff70c8d11a25 (diff)
downloadapr-0f63af2a885695fc864551282d15957bed69099f.tar.gz
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! git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1561265 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'shmem')
-rw-r--r--shmem/unix/shm.c55
1 files changed, 22 insertions, 33 deletions
diff --git a/shmem/unix/shm.c b/shmem/unix/shm.c
index 90dc3061a..3fb20123d 100644
--- a/shmem/unix/shm.c
+++ b/shmem/unix/shm.c
@@ -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;
+/* 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;
- len = strlen(filename);
- if (filename[0] != '/') {
- ++len;
+ for( ; *p; p++) {
+ retval = retval * a + (*p);
+ a *= b;
}
- if (len > NAME_MAX) {
- len = NAME_MAX;
- }
- /* 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