r10355: Merge back the clear-if-first fix from Samba4. Couldn't wait tridge, sorry...
authorJeremy Allison <jra@samba.org>
Tue, 20 Sep 2005 17:33:07 +0000 (17:33 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:03:41 +0000 (11:03 -0500)
Jeremy.
(This used to be commit b1722b7bd1eaabb725218a4fc5c8b012f0a1a0af)

source3/tdb/tdb.c

index 908657b355a6747c21214f6ce550f1fa6cdbe7d2..5d70c046d37fda2859a26fc05ca76732f677784c 100644 (file)
@@ -2071,6 +2071,11 @@ int tdb_reopen(TDB_CONTEXT *tdb)
                TDB_LOG((tdb, 0, "tdb_reopen: open failed (%s)\n", strerror(errno)));
                goto fail;
        }
+       if ((tdb->flags & TDB_CLEAR_IF_FIRST) &&
+                       (tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0) == -1)) {
+               TDB_LOG((tdb, 0, "tdb_reopen: failed to obtain active lock\n"));
+               goto fail;
+       }
        if (fstat(tdb->fd, &st) != 0) {
                TDB_LOG((tdb, 0, "tdb_reopen: fstat failed (%s)\n", strerror(errno)));
                goto fail;
@@ -2080,10 +2085,6 @@ int tdb_reopen(TDB_CONTEXT *tdb)
                goto fail;
        }
        tdb_mmap(tdb);
-       if ((tdb->flags & TDB_CLEAR_IF_FIRST) && (tdb_brlock(tdb, ACTIVE_LOCK, F_RDLCK, F_SETLKW, 0) == -1)) {
-               TDB_LOG((tdb, 0, "tdb_reopen: failed to obtain active lock\n"));
-               goto fail;
-       }
 
        return 0;
 
@@ -2098,8 +2099,6 @@ int tdb_reopen_all(void)
        TDB_CONTEXT *tdb;
 
        for (tdb=tdbs; tdb; tdb = tdb->next) {
-               /* Ensure no clear-if-first. */
-               tdb->flags &= ~TDB_CLEAR_IF_FIRST;
                if (tdb_reopen(tdb) != 0)
                        return -1;
        }