summaryrefslogtreecommitdiff
path: root/source3/tdb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-05-30 03:42:44 +0000
committerAndrew Tridgell <tridge@samba.org>2001-05-30 03:42:44 +0000
commit964d7a66259190548d54af790cb60c63958bff6e (patch)
treebc989670b6b5142b450ae02993d368e0318474e8 /source3/tdb
parentaded7fc8580c0837ad195f652864b9b7481d60ab (diff)
downloadsamba-964d7a66259190548d54af790cb60c63958bff6e.tar.gz
samba-964d7a66259190548d54af790cb60c63958bff6e.tar.bz2
samba-964d7a66259190548d54af790cb60c63958bff6e.zip
added a tdb_open_log() function that opens a tdb and enables logging
of messages from the tdb code into the Samba DEBUG() system just call tdb_open_log() instead of tdb_open() to enable this on any tdb (This used to be commit 3ab770484c6775df2c1a6f69427ebe656702c96c)
Diffstat (limited to 'source3/tdb')
-rw-r--r--source3/tdb/tdb.c2
-rw-r--r--source3/tdb/tdbutil.c33
2 files changed, 34 insertions, 1 deletions
diff --git a/source3/tdb/tdb.c b/source3/tdb/tdb.c
index 463cfc65ca..39e8be3e15 100644
--- a/source3/tdb/tdb.c
+++ b/source3/tdb/tdb.c
@@ -56,7 +56,7 @@
#define TDB_DEAD(r) ((r)->magic == TDB_DEAD_MAGIC)
#define TDB_BAD_MAGIC(r) ((r)->magic != TDB_MAGIC && !TDB_DEAD(r))
#define TDB_HASH_TOP(hash) (FREELIST_TOP + (BUCKET(hash)+1)*sizeof(tdb_off))
-#define TDB_LOG(x) (tdb->log_fn?tdb->log_fn x,0 : 0)
+#define TDB_LOG(x) (tdb->log_fn?((tdb->log_fn x),0) : 0)
/* lock offsets */
#define GLOBAL_LOCK 0
diff --git a/source3/tdb/tdbutil.c b/source3/tdb/tdbutil.c
index 40f5a1246d..c4cbf73034 100644
--- a/source3/tdb/tdbutil.c
+++ b/source3/tdb/tdbutil.c
@@ -321,3 +321,36 @@ int tdb_unpack(char *buf, int bufsize, char *fmt, ...)
no_space:
return -1;
}
+
+/****************************************************************************
+log tdb messages via DEBUG()
+****************************************************************************/
+static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...)
+{
+ va_list ap;
+ char *ptr = NULL;
+
+ va_start(ap, format);
+ vasprintf(&ptr, format, ap);
+ va_end(ap);
+
+ if (!ptr || !*ptr) return;
+
+ DEBUG(level, ("tdb(%s): %s", tdb->name, ptr));
+}
+
+
+
+/* like tdb_open() but also setup a logging function that redirects to
+ the samba DEBUG() system */
+TDB_CONTEXT *tdb_open_log(char *name, int hash_size, int tdb_flags,
+ int open_flags, mode_t mode)
+{
+ TDB_CONTEXT *tdb = tdb_open(name, hash_size, tdb_flags,
+ open_flags, mode);
+ if (!tdb) return NULL;
+
+ tdb_logging_function(tdb, tdb_log);
+
+ return tdb;
+}