View | Details | Raw Unified | Return to bug 62277
Collapse All | Expand All

(-)srclib/apr/shmem/unix/shm.c (-17 / +25 lines)
Lines 23-41 Link Here
23
#include "apr_strings.h"
23
#include "apr_strings.h"
24
#include "apr_hash.h"
24
#include "apr_hash.h"
25
25
26
#if APR_USE_SHMEM_MMAP_SHM
26
#if APR_USE_SHMEM_MMAP_SHM+0 || APR_USE_SHMEM_SHMGET+0
27
/* 
27
/* See proc_mutex.c, sem_open, and our_ftok for the reason for all this! */
28
 *   For portable use, a shared memory object should be identified by a name of
28
static unsigned int rshash (const char *p)
29
 *   the form /somename; that is, a null-terminated string of up to NAME_MAX
29
{
30
 *   (i.e., 255) characters consisting of an initial slash, followed by one or
31
 *   more characters, none of which are slashes.
32
 */
33
#ifndef NAME_MAX
34
#define NAME_MAX 255
35
#endif
36
37
/* See proc_mutex.c and sem_open for the reason for all this! */
38
static unsigned int rshash (const char *p) {
39
    /* hash function from Robert Sedgwicks 'Algorithms in C' book */
30
    /* hash function from Robert Sedgwicks 'Algorithms in C' book */
40
    unsigned int b    = 378551;
31
    unsigned int b    = 378551;
41
    unsigned int a    = 63689;
32
    unsigned int a    = 63689;
Lines 48-54 Link Here
48
39
49
    return retval;
40
    return retval;
50
}
41
}
42
#endif
51
43
44
#if APR_USE_SHMEM_MMAP_SHM
45
/* 
46
 *   For portable use, a shared memory object should be identified by a name of
47
 *   the form /somename; that is, a null-terminated string of up to NAME_MAX
48
 *   (i.e., 255) characters consisting of an initial slash, followed by one or
49
 *   more characters, none of which are slashes.
50
 */
51
#ifndef NAME_MAX
52
#define NAME_MAX 255
53
#endif
54
52
static const char *make_shm_open_safe_name(const char *filename,
55
static const char *make_shm_open_safe_name(const char *filename,
53
                                           apr_pool_t *pool)
56
                                           apr_pool_t *pool)
54
{
57
{
Lines 62-69 static const char *make_shm_open_safe_name(const c Link Here
62
    flen = strlen(filename);
65
    flen = strlen(filename);
63
    h1 = (apr_hashfunc_default(filename, &flen) & 0xffffffff);
66
    h1 = (apr_hashfunc_default(filename, &flen) & 0xffffffff);
64
    h2 = (rshash(filename) & 0xffffffff);
67
    h2 = (rshash(filename) & 0xffffffff);
68
65
    return apr_psprintf(pool, "/ShM.%xH%x", h1, h2);
69
    return apr_psprintf(pool, "/ShM.%xH%x", h1, h2);
66
67
}
70
}
68
#endif
71
#endif
69
72
Lines 72-80 static key_t our_ftok(const char *filename) Link Here
72
{
75
{
73
    /* to help avoid collisions while still using
76
    /* to help avoid collisions while still using
74
     * an easily recreated proj_id */
77
     * an easily recreated proj_id */
75
    apr_ssize_t slen = strlen(filename);
78
    apr_ssize_t flen;
76
    return ftok(filename,
79
    unsigned int h1, h2;
77
                (int)apr_hashfunc_default(filename, &slen));
80
81
    flen = strlen(filename);
82
    h1 = apr_hashfunc_default(filename, &flen);
83
    h2 = rshash(filename);
84
85
    return ftok(filename, h1 ^ h2);
78
}
86
}
79
#endif
87
#endif
80
88

Return to bug 62277