tdb2: return TDB_ERR_RDONLY if trying to start a transaction on a R/O tdb.
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 13 Sep 2011 21:45:13 +0000 (07:15 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 13 Sep 2011 21:45:13 +0000 (07:15 +0930)
This is more accurate than returning TDB_ERR_EINVAL.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(Imported from CCAN commit 91436a25574597dbd1fd2de5bcd5826a234100d6)

lib/tdb2/transaction.c

index eda65c520842240e871ed3439378432f102a4d9c..2f588ef37ad1d8dcb8aed53a0adfdf0bf116d6f4 100644 (file)
@@ -523,13 +523,22 @@ enum TDB_ERROR tdb_transaction_start(struct tdb_context *tdb)
 
        tdb->stats.transactions++;
        /* some sanity checks */
-       if (tdb->read_only || (tdb->flags & TDB_INTERNAL)) {
+       if (tdb->flags & TDB_INTERNAL) {
                return tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL,
+                                                   TDB_LOG_USE_ERROR,
+                                                   "tdb_transaction_start:"
+                                                   " cannot start a"
+                                                   " transaction on an"
+                                                   " internal tdb");
+       }
+
+       if (tdb->read_only) {
+               return tdb->last_error = tdb_logerr(tdb, TDB_ERR_RDONLY,
                                                    TDB_LOG_USE_ERROR,
                                                    "tdb_transaction_start:"
                                                    " cannot start a"
                                                    " transaction on a "
-                                                   "read-only or internal db");
+                                                   " read-only tdb");
        }
 
        /* cope with nested tdb_transaction_start() calls */