From b5b57a0a6b60d4978d099bb9ebed5b766ecd7141 Mon Sep 17 00:00:00 2001 From: John Carr Date: Wed, 29 May 1991 22:27:40 +0000 Subject: [PATCH] Use fcntl(F_SETLK) if POSIX_FILE_LOCKS is defined git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2127 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/kdb/kdb_dbm.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/lib/kdb/kdb_dbm.c b/src/lib/kdb/kdb_dbm.c index f29dac649..cafca7c2f 100644 --- a/src/lib/kdb/kdb_dbm.c +++ b/src/lib/kdb/kdb_dbm.c @@ -22,6 +22,10 @@ static char rcsid_krb_dbm_c[] = #include #include +#ifdef POSIX_FILE_LOCKS +#include +#endif + #define KRB5_DBM_MAX_RETRY 5 /* exclusive or shared lock flags */ @@ -563,13 +567,29 @@ krb5_error_code krb5_dbm_db_lock(mode) int mode; { +#ifdef POSIX_FILE_LOCKS + struct flock fl; +#else int flock_mode; - +#endif if (mylock && (lockmode >= mode)) { mylock++; /* No need to upgrade lock, just return */ return(0); } +#ifdef POSIX_FILE_LOCKS + if (mode == KRB5_DBM_EXCLUSIVE) + fl.l_type = F_WRLCK; + else if (mode == KRB5_DBM_SHARED) + fl.l_type = F_RDLCK; + else + return KRB5_KDB_BADLOCKMODE; + fl.l_whence = 0; + fl.l_start = 0; + fl.l_len = 0; + if (fcntl(dblfd, non_blocking ? F_SETLK : F_SETLKW, &fl) == -1) + return errno; +#else switch (mode) { case KRB5_DBM_EXCLUSIVE: flock_mode = LOCK_EX; @@ -583,9 +603,10 @@ int mode; lockmode = mode; if (non_blocking) flock_mode |= LOCK_NB; - + if (flock(dblfd, flock_mode) < 0) return errno; +#endif mylock++; return 0; } @@ -597,8 +618,18 @@ krb5_dbm_db_unlock() return KRB5_KDB_NOTLOCKED; if (--mylock == 0) { +#ifdef POSIX_FILE_LOCKS + struct flock fl; + fl.l_type = F_UNLCK; + fl.l_whence = 0; + fl.l_start = 0; + fl.l_len = 0; + if (fcntl(dblfd, F_SETLK, &fl) == -1) + return errno; +#else if (flock(dblfd, LOCK_UN) < 0) return errno; +#endif } return 0; } -- 2.26.2