1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-28 01:58:17 +03:00

tdb/tools: Allow tdbtool to r/o open mutexed tdbs

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>
This commit is contained in:
Volker Lendecke 2013-11-15 12:57:06 +01:00 committed by Jeremy Allison
parent bd54feab46
commit 85fe2e8e3b

View File

@ -118,6 +118,33 @@ static double _end_timer(void)
(tp2.tv_usec - tp1.tv_usec)*1.0e-6);
}
#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
@ -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));
}