1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

r2238: the tdb_debug() function was totally bogus - remove it (you can't

convert a ... varargs function to a va_list by just a cast!!)

also mark the tdb log function with PRINTF_ATTRIBUTE() and fixed some
bad format errors in tdb.c that jim found.
This commit is contained in:
Andrew Tridgell 2004-09-07 13:44:49 +00:00 committed by Gerald (Jerry) Carter
parent fdfabbd4a5
commit c26c92eb8f
3 changed files with 23 additions and 36 deletions

View File

@ -89,7 +89,7 @@
/* NB assumes there is a local variable called "tdb" that is the /* NB assumes there is a local variable called "tdb" that is the
* current context, also takes doubly-parenthesized print-style * current context, also takes doubly-parenthesized print-style
* argument. */ * argument. */
#define TDB_LOG(x) (tdb->log_fn?((tdb->log_fn x),0) : 0) #define TDB_LOG(x) tdb->log_fn x
/* lock offsets */ /* lock offsets */
#define GLOBAL_LOCK 0 #define GLOBAL_LOCK 0
@ -277,7 +277,7 @@ static int tdb_lock(TDB_CONTEXT *tdb, int list, int ltype)
if (tdb->locked[list+1].count == 0) { if (tdb->locked[list+1].count == 0) {
if (!tdb->read_only && tdb->header.rwlocks) { if (!tdb->read_only && tdb->header.rwlocks) {
if (tdb_spinlock(tdb, list, ltype)) { if (tdb_spinlock(tdb, list, ltype)) {
TDB_LOG((tdb, 0, "tdb_lock spinlock failed on list ltype=%d\n", TDB_LOG((tdb, 0, "tdb_lock spinlock failed on list %d ltype=%d\n",
list, ltype)); list, ltype));
return -1; return -1;
} }
@ -1755,6 +1755,11 @@ TDB_CONTEXT *tdb_open(const char *name, int hash_size, int tdb_flags,
return tdb_open_ex(name, hash_size, tdb_flags, open_flags, mode, NULL, NULL); return tdb_open_ex(name, hash_size, tdb_flags, open_flags, mode, NULL, NULL);
} }
/* a default logging function */
static void null_log_fn(TDB_CONTEXT *tdb, int level, const char *fmt, ...)
{
}
TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags, TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
int open_flags, mode_t mode, int open_flags, mode_t mode,
@ -1778,7 +1783,7 @@ TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
tdb->lockedkeys = NULL; tdb->lockedkeys = NULL;
tdb->flags = tdb_flags; tdb->flags = tdb_flags;
tdb->open_flags = open_flags; tdb->open_flags = open_flags;
tdb->log_fn = log_fn; tdb->log_fn = log_fn?log_fn:null_log_fn;
tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash; tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash;
if ((open_flags & O_ACCMODE) == O_WRONLY) { if ((open_flags & O_ACCMODE) == O_WRONLY) {
@ -1861,7 +1866,7 @@ TDB_CONTEXT *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
if (tdb_already_open(st.st_dev, st.st_ino)) { if (tdb_already_open(st.st_dev, st.st_ino)) {
TDB_LOG((tdb, 2, "tdb_open_ex: " TDB_LOG((tdb, 2, "tdb_open_ex: "
"%s (%d,%d) is already open in this process\n", "%s (%d,%d) is already open in this process\n",
name, st.st_dev, st.st_ino)); name, (int)st.st_dev, (int)st.st_ino));
errno = EBUSY; errno = EBUSY;
goto fail; goto fail;
} }
@ -2082,7 +2087,7 @@ int tdb_chainunlock_read(TDB_CONTEXT *tdb, TDB_DATA key)
/* register a loging function */ /* register a loging function */
void tdb_logging_function(TDB_CONTEXT *tdb, void (*fn)(TDB_CONTEXT *, int , const char *, ...)) void tdb_logging_function(TDB_CONTEXT *tdb, void (*fn)(TDB_CONTEXT *, int , const char *, ...))
{ {
tdb->log_fn = fn; tdb->log_fn = fn?fn:null_log_fn;
} }

View File

@ -112,8 +112,8 @@ static int tdb_chainlock_with_timeout_internal(TDB_CONTEXT *tdb, TDB_DATA key, u
alarm(0); alarm(0);
TdbCatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN); TdbCatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
if (gotalarm) { if (gotalarm) {
tdb_debug(tdb, 0, "tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n", tdb->log_fn(tdb, 0, "tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n",
timeout, key.dptr, tdb->name ); timeout, key.dptr, tdb->name);
/* TODO: If we time out waiting for a lock, it might /* TODO: If we time out waiting for a lock, it might
* be nice to use F_GETLK to get the pid of the * be nice to use F_GETLK to get the pid of the
* process currently holding the lock and print that * process currently holding the lock and print that
@ -492,8 +492,8 @@ size_t tdb_pack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...)
} }
break; break;
default: default:
tdb_debug(tdb, 0,"Unknown tdb_pack format %c in %s\n", tdb->log_fn(tdb, 0,"Unknown tdb_pack format %c in %s\n",
c, fmt); c, fmt);
len = 0; len = 0;
break; break;
} }
@ -507,8 +507,8 @@ size_t tdb_pack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...)
va_end(ap); va_end(ap);
tdb_debug(tdb, 18,"tdb_pack(%s, %d) -> %d\n", tdb->log_fn(tdb, 18,"tdb_pack(%s, %d) -> %d\n",
fmt0, bufsize0, (int)PTR_DIFF(buf, buf0)); fmt0, bufsize0, (int)PTR_DIFF(buf, buf0));
return PTR_DIFF(buf, buf0); return PTR_DIFF(buf, buf0);
} }
@ -599,7 +599,7 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...)
memcpy(*b, buf+4, *i); memcpy(*b, buf+4, *i);
break; break;
default: default:
tdb_debug(tdb, 0, "Unknown tdb_unpack format %c in %s\n", tdb->log_fn(tdb, 0, "Unknown tdb_unpack format %c in %s\n",
c, fmt); c, fmt);
len = 0; len = 0;
@ -612,8 +612,8 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...)
va_end(ap); va_end(ap);
tdb_debug(tdb, 18, "tdb_unpack(%s, %d) -> %d\n", tdb->log_fn(tdb, 18, "tdb_unpack(%s, %d) -> %d\n",
fmt0, bufsize0, (int)PTR_DIFF(buf, buf0)); fmt0, bufsize0, (int)PTR_DIFF(buf, buf0));
return PTR_DIFF(buf, buf0); return PTR_DIFF(buf, buf0);
@ -621,22 +621,6 @@ int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...)
return -1; return -1;
} }
/****************************************************************************
Print out debug messages.
****************************************************************************/
void tdb_debug(TDB_CONTEXT *tdb, int level, const char *fmt, ...)
{
va_list ap;
if (tdb->log_fn == NULL) {
return;
}
va_start(ap, fmt);
tdb->log_fn(tdb, level, fmt, ap);
va_end(ap);
}
/**************************************************************************** /****************************************************************************
Allow tdb_delete to be used as a tdb_traversal_fn. Allow tdb_delete to be used as a tdb_traversal_fn.
****************************************************************************/ ****************************************************************************/
@ -669,11 +653,11 @@ TDB_LIST_NODE *tdb_search_keys(TDB_CONTEXT *tdb, const char* pattern)
char *key_str = (char*) strndup(key.dptr, key.dsize); char *key_str = (char*) strndup(key.dptr, key.dsize);
#if 0 #if 0
if (!key_str) { if (!key_str) {
tdb_debug(tdb, 0, "tdb_search_keys: strndup() failed!\n"); tdb->log_fn(tdb, 0, "tdb_search_keys: strndup() failed!\n");
smb_panic("strndup failed!\n"); smb_panic("strndup failed!\n");
} }
#endif #endif
tdb_debug(tdb, 18, "checking %s for match to pattern %s\n", key_str, pattern); tdb->log_fn(tdb, 18, "checking %s for match to pattern %s\n", key_str, pattern);
next = tdb_nextkey(tdb, key); next = tdb_nextkey(tdb, key);
@ -686,7 +670,7 @@ TDB_LIST_NODE *tdb_search_keys(TDB_CONTEXT *tdb, const char* pattern)
DLIST_ADD_END(list, rec, TDB_LIST_NODE *); DLIST_ADD_END(list, rec, TDB_LIST_NODE *);
tdb_debug(tdb, 18, "checking %s matched pattern %s\n", key_str, pattern); tdb->log_fn(tdb, 18, "checking %s matched pattern %s\n", key_str, pattern);
} else { } else {
free(key.dptr); free(key.dptr);
} }

View File

@ -101,13 +101,11 @@ typedef struct tdb_context {
struct tdb_context *next; /* all tdbs to avoid multiple opens */ struct tdb_context *next; /* all tdbs to avoid multiple opens */
dev_t device; /* uniquely identifies this tdb */ dev_t device; /* uniquely identifies this tdb */
ino_t inode; /* uniquely identifies this tdb */ ino_t inode; /* uniquely identifies this tdb */
void (*log_fn)(struct tdb_context *tdb, int level, const char *, ...); /* logging function */ void (*log_fn)(struct tdb_context *tdb, int level, const char *, ...) PRINTF_ATTRIBUTE(3,4); /* logging function */
u32 (*hash_fn)(TDB_DATA *key); u32 (*hash_fn)(TDB_DATA *key);
int open_flags; /* flags used in the open - needed by reopen */ int open_flags; /* flags used in the open - needed by reopen */
} TDB_CONTEXT; } TDB_CONTEXT;
void tdb_debug(TDB_CONTEXT *, int , const char *, ...);
typedef int (*tdb_traverse_func)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *); typedef int (*tdb_traverse_func)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *);
typedef void (*tdb_log_func)(TDB_CONTEXT *, int , const char *, ...); typedef void (*tdb_log_func)(TDB_CONTEXT *, int , const char *, ...);
typedef u32 (*tdb_hash_func)(TDB_DATA *key); typedef u32 (*tdb_hash_func)(TDB_DATA *key);