summaryrefslogtreecommitdiff
path: root/locks
diff options
context:
space:
mode:
authordavi <davi@13f79535-47bb-0310-9956-ffa450edef68>2007-06-29 15:08:15 +0000
committerdavi <davi@13f79535-47bb-0310-9956-ffa450edef68>2007-06-29 15:08:15 +0000
commitb8ad51e34d36fabf7f84dffe6c52a6df5ef1014b (patch)
tree63c993ca8ad20c7a91f0ff3a4df454d5ebf509b8 /locks
parent3880e6b4263a79db31497f42e215b8c0801da623 (diff)
downloadlibapr-b8ad51e34d36fabf7f84dffe6c52a6df5ef1014b.tar.gz
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. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@551921 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks')
-rw-r--r--locks/unix/proc_mutex.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c
index 841ad6bd8..c6fdcd918 100644
--- a/locks/unix/proc_mutex.c
+++ b/locks/unix/proc_mutex.c
@@ -79,23 +79,22 @@ static apr_status_t proc_mutex_posix_create(apr_proc_mutex_t *new_mutex,
* 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) {