From 02031cd6705def3aca69c59e5798fc7c4a3482c9 Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Wed, 16 Jul 2014 13:11:07 +0000 Subject: Merge r1610854 from trunk: Resolve failures with the POSIX sem implementation of APR process mutexes (and thus global mutexes) in environments which receive signals. EINTR is now handled on the sem_* calls that are documented as exposing EINTR in the Linux, FreeBSD, and/or Solaris docs. There are a few other calls that haven't been updated: sem_unlink(), sem_post(), and sem_close(). git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1610993 13f79535-47bb-0310-9956-ffa450edef68 --- locks/unix/proc_mutex.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'locks') diff --git a/locks/unix/proc_mutex.c b/locks/unix/proc_mutex.c index cb6bad55e..7eff5e3f3 100644 --- a/locks/unix/proc_mutex.c +++ b/locks/unix/proc_mutex.c @@ -125,7 +125,9 @@ static apr_status_t proc_mutex_posix_create(apr_proc_mutex_t *new_mutex, usec = apr_time_usec(now); apr_snprintf(semname, sizeof(semname), "/ApR.%lxZ%lx", sec, usec); } - psem = sem_open(semname, O_CREAT | O_EXCL, 0644, 1); + do { + psem = sem_open(semname, O_CREAT | O_EXCL, 0644, 1); + } while (psem == (sem_t *)SEM_FAILED && errno == EINTR); if (psem == (sem_t *)SEM_FAILED) { if (errno == ENAMETOOLONG) { /* Oh well, good try */ @@ -133,7 +135,9 @@ static apr_status_t proc_mutex_posix_create(apr_proc_mutex_t *new_mutex, } else { return errno; } - psem = sem_open(semname, O_CREAT | O_EXCL, 0644, 1); + do { + psem = sem_open(semname, O_CREAT | O_EXCL, 0644, 1); + } while (psem == (sem_t *)SEM_FAILED && errno == EINTR); } if (psem == (sem_t *)SEM_FAILED) { @@ -151,7 +155,12 @@ static apr_status_t proc_mutex_posix_create(apr_proc_mutex_t *new_mutex, static apr_status_t proc_mutex_posix_acquire(apr_proc_mutex_t *mutex) { - if (sem_wait(mutex->psem_interproc) < 0) { + int rc; + + do { + rc = sem_wait(mutex->psem_interproc); + } while (rc < 0 && errno == EINTR); + if (rc < 0) { return errno; } mutex->curr_locked = 1; @@ -160,7 +169,12 @@ static apr_status_t proc_mutex_posix_acquire(apr_proc_mutex_t *mutex) static apr_status_t proc_mutex_posix_tryacquire(apr_proc_mutex_t *mutex) { - if (sem_trywait(mutex->psem_interproc) < 0) { + int rc; + + do { + rc = sem_trywait(mutex->psem_interproc); + } while (rc < 0 && errno == EINTR); + if (rc < 0) { if (errno == EAGAIN) { return APR_EBUSY; } -- cgit v1.2.1