apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Jagielski <...@jaguNET.com>
Subject honor fname for Posix sem creation
Date Thu, 27 Mar 2003 18:10:26 GMT
Comments?? :)


Index: locks/unix/proc_mutex.c
===================================================================
RCS file: /home/cvs/apr/locks/unix/proc_mutex.c,v
retrieving revision 1.28
diff -u -r1.28 proc_mutex.c
--- locks/unix/proc_mutex.c     23 Feb 2003 16:40:31 -0000      1.28
+++ locks/unix/proc_mutex.c     27 Mar 2003 17:50:48 -0000
@@ -91,10 +91,8 @@
 {
     sem_t *psem;
     apr_status_t stat;
+    const char *goodfname = fname;
     char semname[31];
-    apr_time_t now;
-    unsigned long sec;
-    unsigned long usec;
     
     new_mutex->interproc = apr_palloc(new_mutex->pool,
                                       sizeof(*new_mutex->interproc));
@@ -105,8 +103,8 @@
      *   - be at most 14 chars
      *   - be unique and not match anything on the filesystem
      *
-     * Because of this, we ignore fname, and try our
-     * own naming system. We tuck the name away, since it might
+     * Because of this, we first try fname and if that fails we 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.
@@ -123,26 +121,34 @@
      * help here however...
      *
      */
-    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((const char *) semname, O_CREAT, 0644, 1);
-    if ((psem == (sem_t *)SEM_FAILED) && (errno == ENAMETOOLONG)) {
-        /* Oh well, good try */
-        semname[13] = '\0';
+    if ( (goodfname == NULL) ||
+        ((psem = sem_open(goodfname,O_CREAT,0644,1)) == (sem_t *)SEM_FAILED)) {
+        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((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;
-        proc_mutex_posix_cleanup(new_mutex);
-        return stat;
+        if (psem == (sem_t *)SEM_FAILED) {
+            stat = errno;
+            proc_mutex_posix_cleanup(new_mutex);
+            return stat;
+        }
+        goodfname = semname;
     }
     /* Ahhh. The joys of Posix sems. Predelete it... */
-    sem_unlink((const char *) semname);
+    sem_unlink((const char *) goodfname);
     new_mutex->interproc->filedes = (int)psem; /* Ugg */
-    new_mutex->fname = apr_pstrdup(new_mutex->pool, semname);
+    new_mutex->fname = apr_pstrdup(new_mutex->pool, goodfname);
     apr_pool_cleanup_register(new_mutex->pool, (void *)new_mutex,
                               apr_proc_mutex_cleanup, 
                               apr_pool_cleanup_null);

-- 
===========================================================================
   Jim Jagielski   [|]   jim@jaguNET.com   [|]   http://www.jaguNET.com/
      "A society that will trade a little liberty for a little order
             will lose both and deserve neither" - T.Jefferson

Mime
View raw message