diff options
Diffstat (limited to 'lib/tdb')
-rw-r--r-- | lib/tdb/tools/tdbdump.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/lib/tdb/tools/tdbdump.c b/lib/tdb/tools/tdbdump.c index 027fda3d42..bb11200ec4 100644 --- a/lib/tdb/tools/tdbdump.c +++ b/lib/tdb/tools/tdbdump.c @@ -51,19 +51,55 @@ static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *stat return 0; } +static void log_stderr(struct tdb_context *tdb, enum tdb_debug_level level, + const char *fmt, ...) +{ + va_list ap; + char *ptr = NULL; + int debuglevel = 0; + int ret; + const char *name = tdb_name(tdb); + const char *prefix = ""; + + if (!name) + name = "unnamed"; + + switch (level) { + case TDB_DEBUG_ERROR: + prefix = "ERROR: "; + break; + case TDB_DEBUG_WARNING: + prefix = "WARNING: "; + break; + case TDB_DEBUG_TRACE: + return; + + default: + case TDB_DEBUG_FATAL: + prefix = "FATAL: "; + break; + } + + va_start(ap, fmt); + fprintf(stderr, "tdb(%s): %s", name, prefix); + vfprintf(stderr, fmt, ap); + va_end(ap); +} + static int dump_tdb(const char *fname, const char *keyname) { TDB_CONTEXT *tdb; TDB_DATA key, value; + struct tdb_logging_context logfn = { log_stderr }; - tdb = tdb_open(fname, 0, 0, O_RDONLY, 0); + tdb = tdb_open_ex(fname, 0, 0, O_RDONLY, 0, &logfn, NULL); if (!tdb) { printf("Failed to open %s\n", fname); return 1; } if (!keyname) { - tdb_traverse(tdb, traverse_fn, NULL); + return tdb_traverse(tdb, traverse_fn, NULL) == -1 ? 1 : 0; } else { key.dptr = discard_const_p(uint8_t, keyname); key.dsize = strlen(keyname); |