summaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2011-06-20 18:40:32 +0930
committerRusty Russell <rusty@rustcorp.com.au>2011-06-20 11:18:35 +0200
commitca1936fbb26af0ee8d0421ae6a4e07a0f62311d9 (patch)
treea2173ebf5126bc9d5fbdcfddbf66e76face39482 /lib/util
parent9eaaf1fc67697a640260169ec26510806105e91f (diff)
downloadsamba-ca1936fbb26af0ee8d0421ae6a4e07a0f62311d9.tar.gz
samba-ca1936fbb26af0ee8d0421ae6a4e07a0f62311d9.tar.bz2
samba-ca1936fbb26af0ee8d0421ae6a4e07a0f62311d9.zip
tdb_compat: use tdb_open_compat.
This is a helper for the common case of opening a tdb with a logging function, but it doesn't do all the work, since TDB1 and TDB2's log functions are different types. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/tdb_wrap.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/util/tdb_wrap.c b/lib/util/tdb_wrap.c
index b19b4fe67f..71aea5e36c 100644
--- a/lib/util/tdb_wrap.c
+++ b/lib/util/tdb_wrap.c
@@ -23,6 +23,31 @@
#include "lib/util/dlinklist.h"
#include "lib/util/tdb_wrap.h"
+/* FIXME: TDB2 does this internally, so no need to wrap multiple opens! */
+#if BUILD_TDB2
+static void tdb_wrap_log(struct tdb_context *tdb,
+ enum tdb_log_level level,
+ const char *message,
+ void *unused)
+{
+ int dl;
+ const char *name = tdb_name(tdb);
+
+ switch (level) {
+ case TDB_LOG_USE_ERROR:
+ case TDB_LOG_ERROR:
+ dl = 0;
+ break;
+ case TDB_LOG_WARNING:
+ dl = 2;
+ break;
+ default:
+ dl = 0;
+ }
+
+ DEBUG(dl, ("tdb(%s): %s", name ? name : "unnamed", message));
+}
+#else
/*
Log tdb messages via DEBUG().
*/
@@ -64,6 +89,7 @@ static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
free(ptr);
}
}
+#endif
struct tdb_wrap_private {
struct tdb_context *tdb;
@@ -89,7 +115,6 @@ static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx,
mode_t mode)
{
struct tdb_wrap_private *result;
- struct tdb_logging_context log_ctx;
result = talloc(mem_ctx, struct tdb_wrap_private);
if (result == NULL) {
@@ -100,8 +125,6 @@ static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx,
goto fail;
}
- log_ctx.log_fn = tdb_wrap_log;
-
#if _SAMBA_BUILD_ == 3
/* This #if _SAMBA_BUILD == 3 is very unfortunate, as it means
* that in the top level build, these options are not
@@ -126,8 +149,8 @@ static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx,
}
#endif
- result->tdb = tdb_open_ex(name, hash_size, tdb_flags,
- open_flags, mode, &log_ctx, NULL);
+ result->tdb = tdb_open_compat(name, hash_size, tdb_flags,
+ open_flags, mode, tdb_wrap_log, NULL);
if (result->tdb == NULL) {
goto fail;
}