You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by da...@apache.org on 2007/06/29 17:08:16 UTC

svn commit: r551921 - /apr/apr/trunk/locks/unix/proc_mutex.c

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) {



Re: svn commit: r551921 - /apr/apr/trunk/locks/unix/proc_mutex.c

Posted by Davi Arnaut <da...@haxent.com.br>.
On 29/06/2007, at 14:07, Joe Orton wrote:

> On Fri, Jun 29, 2007 at 03:08:16PM -0000, davi@apache.org wrote:
>> Author: davi
>> Date: Fri Jun 29 08:08:15 2007
>> New Revision: 551921
>
>> +    if ((psem == (sem_t *)SEM_FAILED)) {
>
> ... minor nit, those parantheses are now redundant.
>

Fixed, thanks.

--
Davi Arnaut

Re: svn commit: r551921 - /apr/apr/trunk/locks/unix/proc_mutex.c

Posted by Joe Orton <jo...@redhat.com>.
On Fri, Jun 29, 2007 at 03:08:16PM -0000, davi@apache.org wrote:
> Author: davi
> Date: Fri Jun 29 08:08:15 2007
> New Revision: 551921

> +    if ((psem == (sem_t *)SEM_FAILED)) {

... minor nit, those parantheses are now redundant.