diff options
author | Volker Lendecke <vl@samba.org> | 2013-06-11 21:03:22 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2013-06-14 20:30:33 +0200 |
commit | cf86f3e81b4e228d5f85cac283c51ca7d5e0cd16 (patch) | |
tree | 9c69e7f1f507e3a108e5ed8f79859001dcee307a /source3/lib | |
parent | c71d6ecbcb463dca64118652e941bb0a162d306f (diff) | |
download | samba-cf86f3e81b4e228d5f85cac283c51ca7d5e0cd16.tar.gz samba-cf86f3e81b4e228d5f85cac283c51ca7d5e0cd16.tar.bz2 samba-cf86f3e81b4e228d5f85cac283c51ca7d5e0cd16.zip |
gencache: Simplify gencache_init a bit
Use the implicit cleanup facility CLEAR_IF_FIRST provides
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/gencache.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index 8ace4d9ad2..08adf2173a 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -58,7 +58,6 @@ 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; @@ -67,24 +66,28 @@ 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|TDB_INCOMPATIBLE_HASH, 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 truncate\n", - cache_fname)); - truncate(cache_fname, 0); - goto again; + + /* + * Retry with CLEAR_IF_FIRST. + * + * Warning: Converting this to dbwrap won't work + * directly. gencache.c does transactions on this tdb, + * and dbwrap forbids this for CLEAR_IF_FIRST + * databases. tdb does allow transactions on + * CLEAR_IF_FIRST databases, so lets use it here to + * clean up a broken database. + */ + cache = tdb_open_log(cache_fname, 0, + TDB_DEFAULT| + TDB_INCOMPATIBLE_HASH| + TDB_CLEAR_IF_FIRST, + open_flags, 0644); } } |