ldb_tdb: Provide better debugging on prepare_commit failures
authorAndrew Bartlett <abartlet@samba.org>
Thu, 30 Mar 2017 01:26:23 +0000 (14:26 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 22 May 2017 23:13:24 +0000 (01:13 +0200)
ltdb_index_transaction_commit() does LDB operations, sets the ldb
error string and returns LDB errors so we should not check the tdb
error code.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_tdb.c

index c0d7a1a432bf5bcd3ce1ef8f91a0cf081d871890..a5feea0284ba153238b5db01f1f88c592e264fe4 100644 (file)
@@ -1121,6 +1121,7 @@ static int ltdb_start_trans(struct ldb_module *module)
 
 static int ltdb_prepare_commit(struct ldb_module *module)
 {
+       int ret;
        void *data = ldb_module_get_private(module);
        struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
 
@@ -1128,15 +1129,21 @@ static int ltdb_prepare_commit(struct ldb_module *module)
                return LDB_SUCCESS;
        }
 
-       if (ltdb_index_transaction_commit(module) != 0) {
+       ret = ltdb_index_transaction_commit(module);
+       if (ret != LDB_SUCCESS) {
                tdb_transaction_cancel(ltdb->tdb);
                ltdb->in_transaction--;
-               return ltdb_err_map(tdb_error(ltdb->tdb));
+               return ret;
        }
 
        if (tdb_transaction_prepare_commit(ltdb->tdb) != 0) {
+               ret = ltdb_err_map(tdb_error(ltdb->tdb));
                ltdb->in_transaction--;
-               return ltdb_err_map(tdb_error(ltdb->tdb));
+               ldb_asprintf_errstring(ldb_module_get_ctx(module),
+                                      "Failure during tdb_transaction_prepare_commit(): %s -> %s",
+                                      tdb_errorstr(ltdb->tdb),
+                                      ldb_strerror(ret));
+               return ret;
        }
 
        ltdb->prepared_commit = true;