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)); }
static const char *make_shm_open_safe_name(const char *filename, apr_pool_t *pool) { apr_ssize_t flen; unsigned int h1, h2; if (filename == NULL) { return NULL; } flen = strlen(filename); h1 = (apr_hashfunc_default(filename, &flen) & 0xffffffff); h2 = (rshash(filename) & 0xffffffff); return apr_psprintf(pool, "/ShM.%xH%x", h1, h2); }
unsigned int HashUUIDForAPR (const char *key_s, apr_ssize_t *len_p) { unsigned int res = 0; char *uuid_s = GetUUIDAsString ((const uint8 *) key_s); if (uuid_s) { apr_ssize_t len = APR_HASH_KEY_STRING; res = apr_hashfunc_default (uuid_s, &len); #if APR_GLOBAL_STORAGE_DEBUG >= STM_LEVEL_FINER PrintLog (STM_LEVEL_FINER, __FILE__, __LINE__, "uuid \"%s\" res %u len %u", uuid_s, res, len); #endif FreeCopiedString (uuid_s); } return res; }
SWITCH_DECLARE(unsigned int) switch_hashfunc_default(const char *key, switch_ssize_t *klen) { return apr_hashfunc_default(key, klen); }
static apr_status_t proc_mutex_posix_create(apr_proc_mutex_t *new_mutex, const char *fname) { #define APR_POSIXSEM_NAME_MIN 13 sem_t *psem; char semname[32]; new_mutex->interproc = apr_palloc(new_mutex->pool, sizeof(*new_mutex->interproc)); /* * This bogusness is to follow what appears to be the * lowest common denominator in Posix semaphore naming: * - start with '/' * - be at most 14 chars * - be unique and not match anything on the filesystem * * Because of this, we use fname to generate a (unique) hash * and use that as the name of the semaphore. If no filename was * given, we create one based on the time. We tuck the name * away, since it might be useful for debugging. We use 2 hashing * functions to try to avoid collisions. * * To make this as robust as possible, we initially try something * larger (and hopefully more unique) and gracefully fail down to the * LCD above. * * NOTE: Darwin (Mac OS X) seems to be the most restrictive * implementation. Versions previous to Darwin 6.2 had the 14 * char limit, but later rev's allow up to 31 characters. * */ if (fname) { apr_ssize_t flen = strlen(fname); char *p = apr_pstrndup(new_mutex->pool, fname, strlen(fname)); unsigned int h1, h2; h1 = (apr_hashfunc_default((const char *)p, &flen) & 0xffffffff); h2 = (rshash(p) & 0xffffffff); apr_snprintf(semname, sizeof(semname), "/ApR.%xH%x", h1, h2); } else { apr_time_t now; unsigned long sec; unsigned long usec; now = apr_time_now(); sec = apr_time_sec(now); usec = apr_time_usec(now); apr_snprintf(semname, sizeof(semname), "/ApR.%lxZ%lx", sec, usec); } psem = sem_open(semname, O_CREAT | O_EXCL, 0644, 1); if (psem == (sem_t *)SEM_FAILED) { if (errno == ENAMETOOLONG) { /* Oh well, good try */ semname[APR_POSIXSEM_NAME_MIN] = '\0'; } else { return errno; } psem = sem_open(semname, O_CREAT | O_EXCL, 0644, 1); } if (psem == (sem_t *)SEM_FAILED) { return errno; } /* Ahhh. The joys of Posix sems. Predelete it... */ sem_unlink(semname); new_mutex->psem_interproc = psem; new_mutex->fname = apr_pstrdup(new_mutex->pool, semname); apr_pool_cleanup_register(new_mutex->pool, (void *)new_mutex, apr_proc_mutex_cleanup, apr_pool_cleanup_null); return APR_SUCCESS; }