tdb: allow tdb_open_ex() with O_RDONLY of TDB_FEATURE_FLAG_MUTEX tdbs.
authorStefan Metzmacher <metze@samba.org>
Tue, 4 Nov 2014 08:51:51 +0000 (09:51 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 20 Nov 2014 15:23:05 +0000 (16:23 +0100)
Bug: https://bugzilla.samba.org/show_bug.cgi?id=10781

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
lib/tdb/common/open.c

index 16a76a347fccd4214000e3c428862fc4108dabb6..3b53fa7e3e4d4f8eff472e01f91f5225e605971b 100644 (file)
@@ -232,6 +232,14 @@ static bool tdb_mutex_open_ok(struct tdb_context *tdb,
 {
        int locked;
 
+       if (tdb->flags & TDB_NOLOCK) {
+               /*
+                * We don't look at locks, so it does not matter to have a
+                * compatible mutex implementation. Allow the open.
+                */
+               return true;
+       }
+
        locked = tdb_nest_lock(tdb, ACTIVE_LOCK, F_WRLCK,
                               TDB_LOCK_NOWAIT|TDB_LOCK_PROBE);
 
@@ -261,14 +269,6 @@ static bool tdb_mutex_open_ok(struct tdb_context *tdb,
                return false;
        }
 
-       if (tdb->flags & TDB_NOLOCK) {
-               /*
-                * We don't look at locks, so it does not matter to have a
-                * compatible mutex implementation. Allow the open.
-                */
-               return true;
-       }
-
 check_local_settings:
 
        if (!(tdb->flags & TDB_MUTEX_LOCKING)) {
@@ -399,7 +399,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
                tdb->read_only = 1;
                /* read only databases don't do locking or clear if first */
                tdb->flags |= TDB_NOLOCK;
-               tdb->flags &= ~TDB_CLEAR_IF_FIRST;
+               tdb->flags &= ~(TDB_CLEAR_IF_FIRST|TDB_MUTEX_LOCKING);
        }
 
        if ((tdb->flags & TDB_ALLOW_NESTING) &&