mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-25 09:09:54 -05:00
Update locking codes.
This commit is contained in:
parent
918b9f8d86
commit
11add79cb1
3 changed files with 40 additions and 35 deletions
|
|
@ -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 <fcntl.h>
|
||||
# endif
|
||||
# include <lutil_lockf.h>
|
||||
# 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 <lutil_lockf.h>
|
||||
# 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 <sys/file.h>
|
||||
# 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 <lutil_lockf.h>
|
||||
# define ldap_lockf(x) lutil_lockf(x)
|
||||
# define ldap_unlockf(x) lutil_unlockf(x)
|
||||
#endif
|
||||
|
||||
#endif /* _AC_UNISTD_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 <stdio.h>
|
||||
#include <ldap_cdefs.h>
|
||||
#include <ac/bytes.h>
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#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_ */
|
||||
|
|
|
|||
|
|
@ -14,28 +14,26 @@
|
|||
#include <stdio.h>
|
||||
#include <ac/unistd.h>
|
||||
|
||||
#if defined(NEED_FCNTL_LOCKING) && defined(HAVE_FCNTL_H)
|
||||
#if defined(NEED_FCNTL_LOCKING)
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
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 */
|
||||
|
|
|
|||
Loading…
Reference in a new issue