Browse Source

tdb2: return TDB_ERR_RDONLY if trying to start a transaction on a R/O tdb.

This is more accurate than returning TDB_ERR_EINVAL.
Rusty Russell 14 years ago
parent
commit
91436a2557
1 changed files with 11 additions and 2 deletions
  1. 11 2
      ccan/tdb2/transaction.c

+ 11 - 2
ccan/tdb2/transaction.c

@@ -523,13 +523,22 @@ enum TDB_ERROR tdb_transaction_start(struct tdb_context *tdb)
 
 
 	tdb->stats.transactions++;
 	tdb->stats.transactions++;
 	/* some sanity checks */
 	/* 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,
 		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_LOG_USE_ERROR,
 						    "tdb_transaction_start:"
 						    "tdb_transaction_start:"
 						    " cannot start a"
 						    " cannot start a"
 						    " transaction on a "
 						    " transaction on a "
-						    "read-only or internal db");
+						    " read-only tdb");
 	}
 	}
 
 
 	/* cope with nested tdb_transaction_start() calls */
 	/* cope with nested tdb_transaction_start() calls */