You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by ji...@apache.org on 2003/02/23 17:40:31 UTC

cvs commit: apr/locks/unix proc_mutex.c

jim         2003/02/23 08:40:31

  Modified:    .        CHANGES
               locks/unix proc_mutex.c
  Log:
  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.
  
  Revision  Changes    Path
  1.380     +3 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.379
  retrieving revision 1.380
  diff -u -r1.379 -r1.380
  --- CHANGES	17 Feb 2003 03:47:10 -0000	1.379
  +++ CHANGES	23 Feb 2003 16:40:31 -0000	1.380
  @@ -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]
   
  
  
  
  1.28      +23 -7     apr/locks/unix/proc_mutex.c
  
  Index: proc_mutex.c
  ===================================================================
  RCS file: /home/cvs/apr/locks/unix/proc_mutex.c,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- proc_mutex.c	7 Jan 2003 00:52:55 -0000	1.27
  +++ proc_mutex.c	23 Feb 2003 16:40:31 -0000	1.28
  @@ -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. 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 @@
       /* 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);