From 7599d59d1afd0814c14953a830ba4a618187e95e Mon Sep 17 00:00:00 2001 From: Matthias Dieter Wallnöfer Date: Wed, 21 Sep 2011 12:54:08 +0200 Subject: ldb:ldb.c/"ldb_wait" - make "ldb_wait" always return an error string Signed-off-by: Andrew Tridgell --- lib/ldb/common/ldb.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'lib/ldb') diff --git a/lib/ldb/common/ldb.c b/lib/ldb/common/ldb.c index d753bf7bd2..4a0d8043cc 100644 --- a/lib/ldb/common/ldb.c +++ b/lib/ldb/common/ldb.c @@ -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; -- cgit