summaryrefslogtreecommitdiff
path: root/locks
diff options
context:
space:
mode:
authorjim <jim@13f79535-47bb-0310-9956-ffa450edef68>2003-02-23 16:40:31 +0000
committerjim <jim@13f79535-47bb-0310-9956-ffa450edef68>2003-02-23 16:40:31 +0000
commit59ef127aee49f1c407607f5abf4fe5e8c138d6f6 (patch)
tree38e7adf405fd9e506b052ac0655c8196aaf70d94 /locks
parent9f75e7eb636c401ad85e54c77ba15c6d6595e455 (diff)
downloadlibapr-59ef127aee49f1c407607f5abf4fe5e8c138d6f6.tar.gz
When we generate our own semaphore name (internally) when using
Posix semaphores, initially try a name more unique (which unfortunately may also be larger than the least-common-denominator in names). If that fails, however, we gracefully use the old naming mechanism. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64371 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks')
-rw-r--r--locks/unix/proc_mutex.c30
1 files changed, 23 insertions, 7 deletions
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);