This has bugged more for awhile. We should be a bit more robust if
we can. I'm almost tempted to 1st try what's passed in fname...
Comments?
Index: locks/unix/proc_mutex.c
===================================================================
RCS file: /home/cvs/apr/locks/unix/proc_mutex.c,v
retrieving revision 1.27
diff -u -r1.27 proc_mutex.c
--- locks/unix/proc_mutex.c 7 Jan 2003 00:52:55 -0000 1.27
+++ locks/unix/proc_mutex.c 22 Feb 2003 16:40:39 -0000
@@ -91,9 +91,10 @@
{
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 @@
* - 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.
+ *
+ * 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. To
+ * make this as robust as possible, we initially try something
+ * larger (and hopefully more unique)
*
* 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 @@
/* 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);
--
===========================================================================
Jim Jagielski [|] [EMAIL PROTECTED] [|] http://www.jaguNET.com/
"A society that will trade a little liberty for a little order
will lose both and deserve neither" - T.Jefferson