diff options
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | locks/unix/proc_mutex.c | 30 |
2 files changed, 26 insertions, 7 deletions
@@ -1,5 +1,8 @@ Changes with APR 0.9.2 + *) When generating a semaphore name for posixsem locking, try to + be a little more robust (and unique). [Jim Jagielski] + *) Add functions apr_env_get, apr_env_set and apr_env_delete for manipulating the environment. [Branko Cibej] diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c index 67656d867..2d3eebf2d 100644 --- a/locks/unix/proc_mutex.c +++ b/locks/unix/proc_mutex.c @@ -91,9 +91,10 @@ static apr_status_t proc_mutex_posix_create(apr_proc_mutex_t *new_mutex, { sem_t *psem; apr_status_t stat; - char semname[14]; + char semname[31]; apr_time_t now; - unsigned long epoch; + unsigned long sec; + unsigned long usec; new_mutex->interproc = apr_palloc(new_mutex->pool, sizeof(*new_mutex->interproc)); @@ -104,20 +105,34 @@ static apr_status_t proc_mutex_posix_create(apr_proc_mutex_t *new_mutex, * - be at most 14 chars * - be unique and not match anything on the filesystem * - * Because of this, we ignore fname and craft our own. + * Because of this, we ignore fname, and try our + * own naming system. We tuck the name away, since it might + * be useful for debugging. 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. * * FIXME: There is a small window of opportunity where * instead of getting a new semaphore descriptor, we get * a previously obtained one. This can happen if the requests - * are made at the "same time" (within a second, due to the - * apr_time_now() call) and in the small span of time between + * are made at the "same time" and in the small span of time between * the sem_open and the sem_unlink. Use of O_EXCL does not * help here however... + * */ now = apr_time_now(); - epoch = apr_time_sec(now); - apr_snprintf(semname, sizeof(semname), "/ApR.%lx", epoch); + sec = apr_time_sec(now); + usec = apr_time_usec(now); + apr_snprintf(semname, sizeof(semname), "/ApR.%lxZ%lx", sec, usec); psem = sem_open((const char *) semname, O_CREAT, 0644, 1); + if ((psem == (sem_t *)SEM_FAILED) && (errno == ENAMETOOLONG)) { + /* Oh well, good try */ + semname[13] = '\0'; + psem = sem_open((const char *) semname, O_CREAT, 0644, 1); + } if (psem == (sem_t *)SEM_FAILED) { stat = errno; @@ -127,6 +142,7 @@ static apr_status_t proc_mutex_posix_create(apr_proc_mutex_t *new_mutex, /* Ahhh. The joys of Posix sems. Predelete it... */ sem_unlink((const char *) semname); new_mutex->interproc->filedes = (int)psem; /* Ugg */ + 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); |