mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-09 02:52:04 +08:00
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.
This commit is contained in:
parent
f4161b5bf8
commit
598b7473fe
@ -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_
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -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 ) {
|
||||
|
@ -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 ) {
|
||||
|
Loading…
Reference in New Issue
Block a user