From b7b73bc0c09f1b1d321c7aad3583b4b366207c7a Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Mon, 15 Oct 1990 16:53:21 +0000 Subject: [PATCH] Changes to export kdb5_db_lock and kdb5_db_unlock to the API.... changed the locking routines to allow recursive locks. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1252 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/kdb/kdb_dbm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib/kdb/kdb_dbm.c b/src/lib/kdb/kdb_dbm.c index 964074af4..bc2fd26b0 100644 --- a/src/lib/kdb/kdb_dbm.c +++ b/src/lib/kdb/kdb_dbm.c @@ -38,6 +38,7 @@ extern int errno; static int dblfd = -1; static int mylock = 0; +static int lockmode = 0; static int inited = 0; static char default_db_name[] = DEFAULT_DBM_FILE; @@ -234,7 +235,7 @@ time_t *age; if (!okname) return ENOMEM; if (stat (okname, &st) < 0) - *age = 0; + *age = -1; else *age = st.st_mtime; @@ -543,9 +544,10 @@ int mode; { int flock_mode; - if (mylock) /* Detect lock call when lock already - * locked */ - return KRB5_KDB_RECURSIVELOCK; + if (mylock && (lockmode >= mode)) { + mylock++; /* No need to upgrade lock, just return */ + return(0); + } switch (mode) { case KRB5_DBM_EXCLUSIVE: @@ -557,6 +559,7 @@ int mode; default: return KRB5_KDB_BADLOCKMODE; } + lockmode = mode; if (non_blocking) flock_mode |= LOCK_NB; @@ -572,9 +575,10 @@ krb5_dbm_db_unlock() if (!mylock) /* lock already unlocked */ return KRB5_KDB_NOTLOCKED; - if (flock(dblfd, LOCK_UN) < 0) - return errno; - mylock = 0; + if (--mylock) { + if (flock(dblfd, LOCK_UN) < 0) + return errno; + } return 0; } -- 2.26.2