apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r551921 - /apr/apr/trunk/locks/unix/proc_mutex.c
Date Fri, 29 Jun 2007 15:08:16 GMT
Author: davi
Date: Fri Jun 29 08:08:15 2007
New Revision: 551921

URL: http://svn.apache.org/viewvc?view=rev&rev=551921
Log:
The use of O_EXCL does help, better fail then use a semaphore not owned
by the caller. The O_EXCL flag guarantees the open will fail if the named
semaphore already exists and if it fails with EEXIST, a new semaphore name
is tried.

Modified:
    apr/apr/trunk/locks/unix/proc_mutex.c

Modified: apr/apr/trunk/locks/unix/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/unix/proc_mutex.c?view=diff&rev=551921&r1=551920&r2=551921
==============================================================================
--- apr/apr/trunk/locks/unix/proc_mutex.c (original)
+++ apr/apr/trunk/locks/unix/proc_mutex.c Fri Jun 29 08:08:15 2007
@@ -79,23 +79,22 @@
      * 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" 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();
     sec = apr_time_sec(now);
     usec = apr_time_usec(now);
     apr_snprintf(semname, sizeof(semname), "/ApR.%lxZ%lx", sec, usec);
-    psem = sem_open(semname, O_CREAT, 0644, 1);
-    if ((psem == (sem_t *)SEM_FAILED) && (errno == ENAMETOOLONG)) {
-        /* Oh well, good try */
-        semname[13] = '\0';
-        psem = sem_open(semname, O_CREAT, 0644, 1);
+    psem = sem_open(semname, O_CREAT | O_EXCL, 0644, 1);
+    if ((psem == (sem_t *)SEM_FAILED)) {
+        if (errno == ENAMETOOLONG) {
+            /* Oh well, good try */
+            semname[13] = '\0';
+        } else if (errno == EEXIST) {
+            apr_snprintf(semname, sizeof(semname), "/ApR.%lxZ%lx", usec, sec);
+        } else {
+            return errno;
+        }
+        psem = sem_open(semname, O_CREAT | O_EXCL, 0644, 1);
     }
 
     if (psem == (sem_t *)SEM_FAILED) {



Mime
View raw message