From: Kurt Zeilenga Date: Fri, 26 Mar 1999 17:43:23 +0000 (+0000) Subject: Update locking codes. X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~329 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=11add79cb131e2ace75337c84c9170035a159aa5;p=openldap Update locking codes. --- diff --git a/include/ac/unistd.h b/include/ac/unistd.h index b4baba4fe6..0162d49ca4 100644 --- a/include/ac/unistd.h +++ b/include/ac/unistd.h @@ -52,27 +52,42 @@ extern char* getpass LDAP_P((const char *getpass)); extern char *mktemp(char *); #endif -/* use _POSIX_VERSION for POSIX.1 code */ - /* Setup file locking macros */ -#if defined (HAVE_LOCKF) && defined (F_LOCK) && defined (F_ULOCK) -# define ldap_lockf(x) lockf(fileno(x),F_LOCK, 0) -# define ldap_unlockf(x) lockf(fileno(x),F_ULOCK, 0) -#elif defined (HAVE_FCNTL_H) && defined (F_WRLCK) && defined (F_UNLCK) -# ifndef NEED_FCNTL_LOCKING -# define NEED_FCNTL_LOCKING +#if !defined( ldap_lockf ) && HAVE_LOCKF && defined( F_LOCK ) +# define ldap_lockf(x) lockf(fileno(x), F_LOCK, 0) +# define ldap_unlockf(x) lockf(fileno(x), F_ULOCK, 0) +#endif + +#if !defined( ldap_lockf ) && HAVE_FCNTL +# ifdef HAVE_FCNTL_H +# include # endif -# include -# define ldap_lockf(x) lutil_ldap_lockf(x) -# define ldap_unlockf(x) lutil_ldap_unlockf(x) -#elif defined (HAVE_FLOCK) && defined (LOCK_EX) && defined (LOCK_UN) + +# ifdef F_WRLCK +# ifndef NEED_FCNTL_LOCKING +# define NEED_FCNTL_LOCKING +# endif +# include +# define ldap_lockf(x) lutil_lockf(x) +# define ldap_unlockf(x) lutil_unlockf(x) +# endif +#endif + +#if !defined( ldap_lockf ) && HAVE_FLOCK # if HAVE_SYS_FILE_H # include # endif -# define ldap_lockf(x) flock(fileno(x),LOCK_EX) -# define ldap_unlockf(x) flock(fileno(x),LOCK_UN) -#else -#error no_suitable_locking_found +# ifdef LOCK_EX +# define ldap_lockf(x) flock(fileno(x), LOCK_EX) +# define ldap_unlockf(x) flock(fileno(x), LOCK_UN) +# endif +#endif + +#if !defined( ldap_lockf ) + /* use some simplistic locking method */ +# include +# define ldap_lockf(x) lutil_lockf(x) +# define ldap_unlockf(x) lutil_unlockf(x) #endif #endif /* _AC_UNISTD_H */ diff --git a/include/lutil_lockf.h b/include/lutil_lockf.h index 9a791d8c3a..166cbe1a40 100644 --- a/include/lutil_lockf.h +++ b/include/lutil_lockf.h @@ -7,26 +7,18 @@ * license is available at http://www.OpenLDAP.org/license.html or * in file LICENSE in the top-level directory of the distribution. */ + /* File locking methods */ +/* only available if fcntl() locking is required */ #ifndef _LUTIL_LOCKF_H_ #define _LUTIL_LOCKF_H_ -#include -#include -#include - -#ifdef HAVE_FCNTL_H -#include -#endif - -#ifdef NEED_FCNTL_LOCKING LDAP_BEGIN_DECL -LDAP_F int lutil_ldap_lockf LDAP_P(( FILE *fs )); -LDAP_F int lutil_ldap_unlockf LDAP_P(( FILE *fs )); +LDAP_F int lutil_lockf LDAP_P(( FILE *fs )); +LDAP_F int lutil_unlockf LDAP_P(( FILE *fs )); LDAP_END_DECL -#endif /* NEED_FCNTL_LOCKING */ #endif /* _LUTIL_LOCKF_H_ */ diff --git a/libraries/liblutil/lockf.c b/libraries/liblutil/lockf.c index 7f0d569f81..7307720dd6 100644 --- a/libraries/liblutil/lockf.c +++ b/libraries/liblutil/lockf.c @@ -14,28 +14,26 @@ #include #include -#if defined(NEED_FCNTL_LOCKING) && defined(HAVE_FCNTL_H) +#if defined(NEED_FCNTL_LOCKING) -#include - -int lutil_ldap_lockf ( FILE *fs ) { +int lutil_lockf ( FILE *fp ) { 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; - return( fcntl( fileno( fs ), F_SETLKW, &file_lock ) ); + return( fcntl( fileno(fp), F_SETLKW, &file_lock ) ); } -int lutil_ldap_unlockf ( FILE *fs ) { +int lutil_unlockf ( FILE *fp ) { 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( fileno( fs ), F_SETLK, &file_lock ) ); + return ( fcntl( fileno(fp), F_SETLK, &file_lock ) ); } #endif /* !HAVE_FILE_LOCKING */