From: Kurt Zeilenga Date: Sun, 28 Mar 1999 22:43:43 +0000 (+0000) Subject: All implementations of lutil_lockf (aka ldap_lockf) block until X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~316 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=598b7473fea63177f65d94a354a9336c6d136097;p=openldap All implementations of lutil_lockf (aka ldap_lockf) block until the lock is acquired. Add comments to that effect. Remove unnecessary busy loops from slapd/lock.c and slurpd/lock.c. --- diff --git a/include/lutil_lockf.h b/include/lutil_lockf.h index 49d2c01e05..2ff75b9bb0 100644 --- a/include/lutil_lockf.h +++ b/include/lutil_lockf.h @@ -8,8 +8,10 @@ * in file LICENSE in the top-level directory of the distribution. */ -/* File locking methods */ -/* only available if fcntl() locking is required */ +/* File locking methods + * + * lutil_lockf() will block until an exclusive lock is acquired. + */ #ifndef _LUTIL_LOCKF_H_ #define _LUTIL_LOCKF_H_ diff --git a/libraries/liblutil/lockf.c b/libraries/liblutil/lockf.c index c21d2a8dfc..3daf88c695 100644 --- a/libraries/liblutil/lockf.c +++ b/libraries/liblutil/lockf.c @@ -17,6 +17,8 @@ * - flock * * Other implementations will be added as needed. + * + * NOTE: lutil_lockf() MUST block until an exclusive lock is acquired. */ #include "portable.h" @@ -51,6 +53,7 @@ #ifdef USE_LOCKF int lutil_lockf ( int fd ) { + /* use F_LOCK instead of F_TLOCK, ie: block */ return lockf( fd, F_LOCK, 0 ); } @@ -62,27 +65,33 @@ int lutil_unlockf ( int fd ) { #ifdef USE_FCNTL int lutil_lockf ( int fd ) { struct flock file_lock; + memset( &file_lock, 0, sizeof( file_lock ) ); file_lock.l_type = F_WRLCK; file_lock.l_whence = SEEK_SET; file_lock.l_start = 0; file_lock.l_len = 0; + + /* use F_SETLKW instead of F_SETLK, ie: block */ return( fcntl( fd, F_SETLKW, &file_lock ) ); } int lutil_unlockf ( int fd ) { struct flock file_lock; + memset( &file_lock, 0, sizeof( file_lock ) ); file_lock.l_type = F_UNLCK; file_lock.l_whence = SEEK_SET; file_lock.l_start = 0; file_lock.l_len = 0; - return( fcntl ( fd, F_SETLK, &file_lock ) ); + + return( fcntl ( fd, F_SETLKW, &file_lock ) ); } #endif #ifdef USE_FLOCK int lutil_lockf ( int fd ) { + /* use LOCK_EX instead of LOCK_EX|LOCK_NB, ie: block */ return flock( fd, LOCK_EX ); } diff --git a/servers/slapd/lock.c b/servers/slapd/lock.c index b23aa9028c..9325389d12 100644 --- a/servers/slapd/lock.c +++ b/servers/slapd/lock.c @@ -30,9 +30,7 @@ lock_fopen( char *fname, char *type, FILE **lfp ) } /* acquire the lock */ - while ( ldap_lockf( fileno(*lfp) ) != 0 ) { - ; /* NULL */ - } + ldap_lockf( fileno(*lfp) ); /* open the log file */ if ( (fp = fopen( fname, type )) == NULL ) { diff --git a/servers/slurpd/lock.c b/servers/slurpd/lock.c index cca1bed3f8..40c61a2517 100644 --- a/servers/slurpd/lock.c +++ b/servers/slurpd/lock.c @@ -53,10 +53,7 @@ lock_fopen( } /* acquire the lock */ - while ( ldap_lockf( fileno(*lfp) ) != 0 ) - { - ; /* NULL */ - } + ldap_lockf( fileno(*lfp) ); /* open the log file */ if ( (fp = fopen( fname, type )) == NULL ) {