summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2013-11-15 12:57:06 +0100
committerJeremy Allison <jra@samba.org>2014-05-22 21:05:15 +0200
commit85fe2e8e3be15370f961561882518aedf137de5f (patch)
treefdd523385df81067075581b7ad9e02fb7dbcfec4
parentbd54feab46d5dfd36c8a1729a46b59757ffe1e6a (diff)
downloadsamba-85fe2e8e3be15370f961561882518aedf137de5f.tar.gz
tdb/tools: Allow tdbtool to r/o open mutexed tdbstdb-1.3.0
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Volker Lendecke <vl@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r--lib/tdb/tools/tdbtool.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/lib/tdb/tools/tdbtool.c b/lib/tdb/tools/tdbtool.c
index c4861178610..2f93e338b85 100644
--- a/lib/tdb/tools/tdbtool.c
+++ b/lib/tdb/tools/tdbtool.c
@@ -119,6 +119,33 @@ static double _end_timer(void)
}
#ifdef PRINTF_ATTRIBUTE
+static void tdb_log_open(struct tdb_context *tdb, enum tdb_debug_level level,
+ const char *format, ...) PRINTF_ATTRIBUTE(3,4);
+#endif
+static void tdb_log_open(struct tdb_context *tdb, enum tdb_debug_level level,
+ const char *format, ...)
+{
+ const char *mutex_msg =
+ "Can use mutexes only with MUTEX_LOCKING or NOLOCK\n";
+ char *p;
+ va_list ap;
+
+ p = strstr(format, mutex_msg);
+ if (p != NULL) {
+ /*
+ * Yes, this is a hack, but we don't want to see this
+ * message on first open, but we want to see
+ * everything else.
+ */
+ return;
+ }
+
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+}
+
+#ifdef PRINTF_ATTRIBUTE
static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...) PRINTF_ATTRIBUTE(3,4);
#endif
static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, const char *format, ...)
@@ -240,7 +267,7 @@ static void create_tdb(const char *tdbname)
static void open_tdb(const char *tdbname)
{
struct tdb_logging_context log_ctx = { NULL, NULL };
- log_ctx.log_fn = tdb_log;
+ log_ctx.log_fn = tdb_log_open;
if (tdb) tdb_close(tdb);
tdb = tdb_open_ex(tdbname, 0,
@@ -248,6 +275,23 @@ static void open_tdb(const char *tdbname)
(disable_lock?TDB_NOLOCK:0),
O_RDWR, 0600,
&log_ctx, NULL);
+
+ log_ctx.log_fn = tdb_log;
+ if (tdb != NULL) {
+ tdb_set_logging_function(tdb, &log_ctx);
+ }
+
+ if ((tdb == NULL) && (errno == EINVAL)) {
+ /*
+ * Retry NOLOCK and readonly. There we want to see all
+ * error messages.
+ */
+ tdb = tdb_open_ex(tdbname, 0,
+ (disable_mmap?TDB_NOMMAP:0) |TDB_NOLOCK,
+ O_RDONLY, 0600,
+ &log_ctx, NULL);
+ }
+
if (!tdb) {
printf("Could not open %s: %s\n", tdbname, strerror(errno));
}