ldb:ldb.c/"ldb_wait" - make "ldb_wait" always return an error string
authorMatthias Dieter Wallnöfer <mdw@samba.org>
Wed, 21 Sep 2011 10:54:08 +0000 (12:54 +0200)
committerAndrew Tridgell <tridge@samba.org>
Tue, 11 Oct 2011 06:42:07 +0000 (08:42 +0200)
Signed-off-by: Andrew Tridgell <tridge@samba.org>
lib/ldb/common/ldb.c

index d753bf7bd247f6233e4ffe03420e44768b0e37b1..4a0d8043cc2c09e9bb901b21ff1aaef15f0d1d66 100644 (file)
@@ -578,25 +578,41 @@ int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type)
        int ret;
 
        if (!handle) {
-               return LDB_ERR_UNAVAILABLE;
+               return ldb_error(handle->ldb, LDB_ERR_UNAVAILABLE, NULL);
        }
 
        if (handle->state == LDB_ASYNC_DONE) {
+               if ((handle->status != LDB_SUCCESS) &&
+                   (handle->ldb->err_string == NULL)) {
+                       /* if no error string was setup by the backend */
+                       ldb_asprintf_errstring(handle->ldb, "ldb_wait: %s (%d)",
+                                              ldb_strerror(handle->status),
+                                              handle->status);
+               }
                return handle->status;
        }
 
        ev = ldb_get_event_context(handle->ldb);
        if (NULL == ev) {
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(handle->ldb);
        }
 
        switch (type) {
        case LDB_WAIT_NONE:
                ret = tevent_loop_once(ev);
                if (ret != 0) {
-                       return LDB_ERR_OPERATIONS_ERROR;
+                       return ldb_operr(handle->ldb);
                }
                if (handle->status != LDB_SUCCESS) {
+                       if (handle->ldb->err_string == NULL) {
+                               /*
+                                * if no error string was setup by the backend
+                                */
+                               ldb_asprintf_errstring(handle->ldb,
+                                                      "ldb_wait: %s (%d)",
+                                                      ldb_strerror(handle->status),
+                                                      handle->status);
+                       }
                        return handle->status;
                }
                break;
@@ -605,13 +621,32 @@ int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type)
                while (handle->state != LDB_ASYNC_DONE) {
                        ret = tevent_loop_once(ev);
                        if (ret != 0) {
-                               return LDB_ERR_OPERATIONS_ERROR;
+                               return ldb_operr(handle->ldb);
                        }
                        if (handle->status != LDB_SUCCESS) {
+                               if  (handle->ldb->err_string == NULL) {
+                                       /*
+                                        * if no error string was setup by the
+                                        * backend
+                                        */
+                                       ldb_asprintf_errstring(handle->ldb,
+                                                              "ldb_wait: %s (%d)",
+                                                              ldb_strerror(handle->status),
+                                                              handle->status);
+                               }
                                return handle->status;
                        }
                }
                if (handle->status != LDB_SUCCESS) {
+                       if (handle->ldb->err_string == NULL) {
+                               /*
+                                * if no error string was setup by the backend
+                                */
+                               ldb_asprintf_errstring(handle->ldb,
+                                                      "ldb_wait: %s (%d)",
+                                                      ldb_strerror(handle->status),
+                                                      handle->status);
+                       }
                        return handle->status;
                }
                break;