struct ctdb_reply_control *reply;
struct ctdb_db *db = req->priv_data;
uint32_t tdb_flags = db->tdb_flags;
+ struct tdb_logging_context log;
/* Never sent the dbpath request? We've failed. */
if (!dbpath_req) {
tdb_flags = db->persistent ? TDB_DEFAULT : TDB_NOSYNC;
tdb_flags |= TDB_DISALLOW_NESTING;
- /* FIXME: Setup logging to go through our logging. */
- db->tdb = tdb_open((char *)reply->data, 0, tdb_flags, O_RDWR, 0);
+ log.log_fn = ctdb_tdb_log_bridge;
+ log.log_private = ctdb;
+ db->tdb = tdb_open_ex((char *)reply->data, 0, tdb_flags, O_RDWR, 0,
+ &log, NULL);
if (db->tdb == NULL) {
DEBUG(db->ctdb, LOG_ERR,
"ctdb_attachdb_recv: failed to tdb_open %s",
DEBUG(ctdb_db->ctdb, LOG_ALERT,
"ctdb_writerecord: record changed under lock?");
break;
- default:
- /* FIXME: replace with proper tdb logging. */
- DEBUG(ctdb_db->ctdb, LOG_CRIT,
- "ctdb_writerecord: tdb error.");
+ default: /* TDB already logged. */
break;
}
return false;
#include <ctdb.h>
#include <ctdb_protocol.h>
#include <syslog.h>
+#include <tdb.h>
#ifndef offsetof
#define offsetof(t,f) ((unsigned int)&((t *)0)->f)
#define DEBUG(ctdb, lvl, format, args...) do { if (lvl <= ctdb_log_level) { ctdb_do_debug(ctdb, lvl, format , ## args ); }} while(0)
-void ctdb_do_debug(struct ctdb_connection *, int, const char *format, ...)
- PRINTF_ATTRIBUTE(3, 4) COLD_ATTRIBUTE;
-
struct message_handler_info;
struct ctdb_reply_call;
void ctdb_cancel_callback(struct ctdb_connection *ctdb,
struct ctdb_request *req,
void *unused);
+
+/* logging.c */
+void ctdb_tdb_log_bridge(struct tdb_context *tdb,
+ enum tdb_debug_level level,
+ const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
+
+void ctdb_do_debug(struct ctdb_connection *, int, const char *format, ...)
+ PRINTF_ATTRIBUTE(3, 4) COLD_ATTRIBUTE;
+
#endif /* _LIBCTDB_PRIVATE_H */
#include <errno.h>
#include <ctdb.h>
#include <string.h>
+#include <tdb.h>
#include "libctdb_private.h"
int ctdb_log_level = LOG_WARNING;
va_end(ap);
}
+/* Attach tdb logging to our ctdb logging. */
+void ctdb_tdb_log_bridge(struct tdb_context *tdb,
+ enum tdb_debug_level level,
+ const char *format, ...)
+{
+ va_list ap;
+ int sev;
+ struct ctdb_connection *ctdb = tdb_get_logging_private(tdb);
+ char *newformat;
+
+ switch (level) {
+ case TDB_DEBUG_FATAL:
+ sev = LOG_CRIT;
+ break;
+ case TDB_DEBUG_ERROR:
+ sev = LOG_ERR;
+ break;
+ case TDB_DEBUG_WARNING:
+ sev = LOG_WARNING;
+ break;
+ case TDB_DEBUG_TRACE:
+ sev = LOG_DEBUG;
+ break;
+ default:
+ sev = LOG_CRIT;
+ }
+
+ if (sev > ctdb_log_level) {
+ return;
+ }
+
+ newformat = malloc(sizeof("TDB error: ") + strlen(format));
+ if (!newformat) {
+ DEBUG(ctdb, LOG_ERR,
+ "memory allocation failure reporting tdb error %s",
+ format);
+ return;
+ }
+
+ /* Prepend TDB error: and remove \n */
+ strcpy(newformat, "TDB error: ");
+ strcat(newformat, format);
+ if (newformat[strlen(newformat)-1] == '\n')
+ newformat[strlen(newformat)-1] = '\0';
+
+ va_start(ap, format);
+ ctdb->log(ctdb->log_priv, sev, newformat, ap);
+ va_end(ap);
+ free(newformat);
+}
+
/* Convenient log helper. */
void ctdb_log_file(FILE *outf, int priority, const char *format, va_list ap)
{