gencache: don't use CLEAR_IF_FIRST as fallback.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 19 Apr 2011 02:36:05 +0000 (12:06 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 19 Apr 2011 02:36:05 +0000 (12:06 +0930)
CLEAR_IF_FIRST only works if *all* openers use that flag.

So just truncate the file: it's racy, but that's what we're doing anyway.

We'd really need a TDB_OPENCHECK_OR_CLEAR flag to do this properly (or in
TDB2, a open hook at the right point).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
source3/lib/gencache.c
source3/libsmb/samlogon_cache.c

index 7a86063de5d77ae4ed8a01208c3174dc4836639b..8d4861a176936b740d01e4dec1748dc5cf5f1014 100644 (file)
@@ -81,14 +81,10 @@ again:
                                return false;
                        }
                        first_try = false;
-                       DEBUG(0, ("gencache_init: tdb_check(%s) failed - retry after CLEAR_IF_FIRST\n",
+                       DEBUG(0, ("gencache_init: tdb_check(%s) failed - retry after truncate\n",
                                  cache_fname));
-                       cache = tdb_open_log(cache_fname, 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, open_flags, 0644);
-                       if (cache) {
-                               tdb_close(cache);
-                               cache = NULL;
-                               goto again;
-                       }
+                       truncate(cache_fname, 0);
+                       goto again;
                }
        }
 
index 590c950a9cc77b98eed38603b78afb85fc564c97..01a528275186a4b32e94c495a216df57224769e7 100644 (file)
@@ -71,16 +71,9 @@ clear:
        }
        first_try = false;
 
-       DEBUG(0,("retry after CLEAR_IF_FIRST for '%s'\n", path));
-       tdb = tdb_open_log(path, 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
-                          O_RDWR | O_CREAT, 0600);
-       if (tdb) {
-               tdb_close(tdb);
-               goto again;
-       }
-       DEBUG(0,("tdb_open_log(%s) with CLEAR_IF_FIRST - failed\n", path));
-
-       return false;
+       DEBUG(0,("retry after truncate for '%s'\n", path));
+       truncate(path, 0);
+       goto again;
 }