s4-ldb: added ldb_error() and ldb_operr()
authorAndrew Tridgell <tridge@samba.org>
Tue, 6 Jul 2010 03:20:19 +0000 (13:20 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 7 Jul 2010 10:14:55 +0000 (20:14 +1000)
These will be used to help avoid the problem we have with hundreds of
places that do "return LDB_ERR_OPERATIONS_ERROR" without an
explanation. It is very difficult to track down ldb errors which don't
have any explanation.

By replacing "return LDB_ERR_OPERATIONS_ERROR;" with "return ldb_operr(ldb);"
we at least get a file:line message in the ldb error string. It isn't
an ideal error message, but it is much better than just "operations
error"

This change also makes ldb_oom() return the error code
(LDB_ERR_OPERATIONS_ERROR) so you can do:

  return ldb_oom(ldb);

instead of:

  ldb_oom(ldb);
  return LDB_ERR_OPERATIONS_ERROR;

source4/lib/ldb/common/ldb.c
source4/lib/ldb/include/ldb_module.h
source4/lib/ldb/wscript

index 07aa6d0985f9aaa44c33e9745d929042af139af5..877f283491f265ee7ea16f91c1f5b11855524d7f 100644 (file)
@@ -285,6 +285,22 @@ void ldb_reset_err_string(struct ldb_context *ldb)
        }
 }
 
+
+
+/*
+  set an ldb error based on file:line
+*/
+int ldb_error_at(struct ldb_context *ldb, int ecode,
+                const char *reason, const char *file, int line)
+{
+       if (reason == NULL) {
+               reason = ldb_strerror(ecode);
+       }
+       ldb_asprintf_errstring(ldb, "%s at %s:%d", reason, file, line);
+       return ecode;
+}
+
+
 #define FIRST_OP_NOERR(ldb, op) do { \
        module = ldb->modules;                                  \
        while (module && module->ops->op == NULL) module = module->next; \
index 2d14634ca813b68f4569bd9004ee4154f761591b..55121a81069f1dbcb59dd811e1cc46f25f8e5598 100644 (file)
@@ -67,8 +67,11 @@ void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level,
 void ldb_debug_add(struct ldb_context *ldb, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
 void ldb_debug_end(struct ldb_context *ldb, enum ldb_debug_level level);
 
-#define ldb_oom(ldb) ldb_debug_set(ldb, LDB_DEBUG_FATAL, "ldb out of memory at %s:%d\n", __FILE__, __LINE__)
+#define ldb_error(ldb, ecode, reason) ldb_error_at(ldb, ecode, reason, __FILE__, __LINE__)
+
+#define ldb_oom(ldb) ldb_error(ldb, LDB_DEBUG_FATAL, "ldb out of memory")
 #define ldb_module_oom(module) ldb_oom(ldb_module_get_ctx(module))
+#define ldb_operr(ldb) ldb_error(ldb, LDB_ERR_OPERATIONS_ERROR, "operations error")
 
 /* The following definitions come from lib/ldb/common/ldb.c  */
 
@@ -152,6 +155,7 @@ int ldb_next_init(struct ldb_module *module);
 void ldb_set_errstring(struct ldb_context *ldb, const char *err_string);
 void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
 void ldb_reset_err_string(struct ldb_context *ldb);
+int ldb_error_at(struct ldb_context *ldb, int ecode, const char *reason, const char *file, int line);
 
 const char *ldb_default_modules_dir(void);
 
index 773925e5c45c56bdbf4a77672440f75c70dd3c0c..3dd4547c0d2fc4146a049558a513e1be9dc15ee1 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 APPNAME = 'ldb'
-VERSION = '0.9.12'
+VERSION = '0.9.13'
 
 blddir = 'bin'