You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by tr...@locus.apache.org on 2000/07/19 18:35:49 UTC

cvs commit: apache-2.0/src/lib/apr/locks/unix crossproc.c

trawick     00/07/19 09:35:49

  Modified:    src      CHANGES
               src/lib/apr/locks/unix crossproc.c
  Log:
  APR lock fixes: when using SysV sems, flock(), or fcntl(), be sure
  to repeat the syscall until we stop getting EINTR.  I noticed a
  related problem at termination (SIGTERM) on FreeBSD when using
  fcntl().  Apache 1.3 had these new loops too.
  
  Revision  Changes    Path
  1.175     +5 -0      apache-2.0/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/CHANGES,v
  retrieving revision 1.174
  retrieving revision 1.175
  diff -u -r1.174 -r1.175
  --- CHANGES	2000/07/16 12:30:59	1.174
  +++ CHANGES	2000/07/19 16:35:47	1.175
  @@ -1,5 +1,10 @@
   Changes with Apache 2.0a5
   
  +  *) APR lock fixes: when using SysV sems, flock(), or fcntl(), be sure
  +     to repeat the syscall until we stop getting EINTR.  I noticed a
  +     related problem at termination (SIGTERM) on FreeBSD when using
  +     fcntl().  Apache 1.3 had these new loops too.  [Jeff Trawick]
  +
     *) The htdocs/ tree has been moved out of the CVS source tree into
        a separate area for easier development.  This has NO EFFECT on
        end-users or Apache installations.  [Ken Coar]
  
  
  
  1.32      +41 -17    apache-2.0/src/lib/apr/locks/unix/crossproc.c
  
  Index: crossproc.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/locks/unix/crossproc.c,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- crossproc.c	2000/06/22 00:35:59	1.31
  +++ crossproc.c	2000/07/19 16:35:48	1.32
  @@ -104,16 +104,26 @@
   
   ap_status_t ap_unix_lock_inter(ap_lock_t *lock)
   {
  -    lock->curr_locked = 1;
  -    if (semop(lock->interproc, &op_on, 1) < 0) {
  +    int rc;
  +
  +    do {
  +        rc = semop(lock->interproc, &op_on, 1);
  +    } while (rc < 0 && errno == EINTR);
  +    if (rc < 0) {
           return errno;
       }
  +    lock->curr_locked = 1;
       return APR_SUCCESS;
   }
   
   ap_status_t ap_unix_unlock_inter(ap_lock_t *lock)
   {
  -    if (semop(lock->interproc, &op_off, 1) < 0) {
  +    int rc;
  +
  +    do {
  +        rc = semop(lock->interproc, &op_off, 1);
  +    } while (rc < 0 && errno == EINTR);
  +    if (rc < 0) {
           return errno;
       }
       lock->curr_locked = 0;
  @@ -260,10 +270,7 @@
       ap_lock_t *lock=lock_;
   
       if (lock->curr_locked == 1) {
  -        if (fcntl(lock->interproc, F_SETLKW, &unlock_it) < 0) {
  -            return errno;
  -        }
  -        lock->curr_locked=0;
  +        return ap_unix_unlock_inter(lock);
       }
       return APR_SUCCESS;
   }    
  @@ -291,16 +298,26 @@
   
   ap_status_t ap_unix_lock_inter(ap_lock_t *lock)
   {
  -    lock->curr_locked=1;
  -    if (fcntl(lock->interproc, F_SETLKW, &lock_it) < 0) {
  +    int rc;
  +
  +    do {
  +        rc = fcntl(lock->interproc, F_SETLKW, &lock_it);
  +    } while (rc < 0 && errno == EINTR);
  +    if (rc < 0) {
           return errno;
       }
  +    lock->curr_locked=1;
       return APR_SUCCESS;
   }
   
   ap_status_t ap_unix_unlock_inter(ap_lock_t *lock)
   {
  -    if (fcntl(lock->interproc, F_SETLKW, &unlock_it) < 0) {
  +    int rc;
  +
  +    do {
  +        rc = fcntl(lock->interproc, F_SETLKW, &unlock_it);
  +    } while (rc < 0 && errno == EINTR);
  +    if (rc < 0) {
           return errno;
       }
       lock->curr_locked=0;
  @@ -334,10 +351,7 @@
       ap_lock_t *lock=lock_;
   
       if (lock->curr_locked == 1) {
  -        if (flock(lock->interproc, LOCK_UN) < 0) {
  -            return errno;
  -        }
  -        lock->curr_locked = 0;
  +        return ap_unix_unlock_inter(lock);
       }
       unlink(lock->fname);
       return APR_SUCCESS;
  @@ -364,16 +378,26 @@
   
   ap_status_t ap_unix_lock_inter(ap_lock_t *lock)
   {
  -    lock->curr_locked = 1;
  -    if (flock(lock->interproc, LOCK_EX) < 0) {
  +    int rc;
  +
  +    do {
  +        rc = flock(lock->interproc, LOCK_EX);
  +    } while (rc < 0 && errno == EINTR);
  +    if (rc < 0) {
           return errno;
       }
  +    lock->curr_locked = 1;
       return APR_SUCCESS;
   }
   
   ap_status_t ap_unix_unlock_inter(ap_lock_t *lock)
   {
  -    if (flock(lock->interproc, LOCK_UN) < 0) {
  +    int rc;
  +
  +    do {
  +        rc = flock(lock->interproc, LOCK_UN);
  +    } while (rc < 0 && errno == EINTR);
  +    if (rc < 0) {
           return errno;
       }
       lock->curr_locked = 0;