diff options
author | Stefan Metzmacher <metze@samba.org> | 2009-12-04 16:46:34 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2009-12-07 19:57:01 +0100 |
commit | 909cd2617fa1c170183664af1fc4253af2dc2f21 (patch) | |
tree | 3d09432fbdd9f1a62ee4c72e44ac90dbef5d1305 /source3/lib | |
parent | 8f19c08072a7a6036d59cf6c2ca6ce17c74b7635 (diff) | |
download | samba-909cd2617fa1c170183664af1fc4253af2dc2f21.tar.gz samba-909cd2617fa1c170183664af1fc4253af2dc2f21.tar.bz2 samba-909cd2617fa1c170183664af1fc4253af2dc2f21.zip |
s3: let gencache_init() use tdb_check()
If the check fails we try to clear the tdb and start
with an empty cache.
metze
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/gencache.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index 4889d7ca62..9a4cbc2cd7 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -55,6 +55,7 @@ static bool gencache_init(void) { char* cache_fname = NULL; int open_flags = O_RDWR|O_CREAT; + bool first_try = true; /* skip file open if it's already opened */ if (cache) return True; @@ -63,7 +64,30 @@ static bool gencache_init(void) DEBUG(5, ("Opening cache file at %s\n", cache_fname)); +again: cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT, open_flags, 0644); + if (cache) { + int ret; + ret = tdb_check(cache, NULL, NULL); + if (ret != 0) { + tdb_close(cache); + cache = NULL; + if (!first_try) { + DEBUG(0, ("gencache_init: tdb_check(%s) failed\n", + cache_fname)); + return false; + } + first_try = false; + DEBUG(0, ("gencache_init: tdb_check(%s) failed - retry after CLEAR_IF_FIRST\n", + cache_fname)); + cache = tdb_open_log(cache_fname, 0, TDB_CLEAR_IF_FIRST, open_flags, 0644); + if (cache) { + tdb_close(cache); + cache = NULL; + goto again; + } + } + } if (!cache && (errno == EACCES)) { open_flags = O_RDONLY; @@ -89,6 +113,7 @@ static bool gencache_init(void) DEBUG(5, ("Opening %s failed: %s\n", cache_fname, strerror(errno))); tdb_close(cache); + cache = NULL; return false; } |