s4:ldb: setup tevent debug functions on a selfcreated event context
authorStefan Metzmacher <metze@samba.org>
Thu, 12 Mar 2009 09:04:02 +0000 (10:04 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 12 Mar 2009 11:04:30 +0000 (12:04 +0100)
metze

source4/lib/ldb/common/ldb.c

index f1b28b6819b7cb20152d44a232b5d4c3d2d1ea79..e17e10dcaafaf8da617d4cd08f98e26420a12b4c 100644 (file)
@@ -47,6 +47,40 @@ static int ldb_context_destructor(void *ptr)
        return 0;
 }
 
+/*
+  this is used to catch debug messages from events
+*/
+static void ldb_tevent_debug(void *context, enum tevent_debug_level level,
+                            const char *fmt, va_list ap)  PRINTF_ATTRIBUTE(3,0);
+
+static void ldb_tevent_debug(void *context, enum tevent_debug_level level,
+                            const char *fmt, va_list ap)
+{
+       struct ldb_context = talloc_get_type_abort(context, struct ldb_context);
+       enum ldb_debug_level ldb_level = LDB_DEBUG_FATAL;
+       char *s = NULL;
+
+       switch (level) {
+       case TEVENT_DEBUG_FATAL:
+               ldb_level = LDB_DEBUG_FATAL;
+               break;
+       case TEVENT_DEBUG_ERROR:
+               ldb_level = LDB_DEBUG_ERROR;
+               break;
+       case TEVENT_DEBUG_WARNING:
+               ldb_level = LDB_DEBUG_WARNING;
+               break;
+       case TEVENT_DEBUG_TRACE:
+               ldb_level = LDB_DEBUG_TRACE;
+               break;
+       };
+
+       vasprintf(&s, fmt, ap);
+       if (!s) return;
+       ldb_debug(ldb, ldb_level, "tevent: %s", s);
+       free(s);
+}
+
 /*
    initialise a ldb context
    The mem_ctx is required
@@ -62,6 +96,7 @@ struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx)
         * until we have them all converted */
        if (ev_ctx == NULL) {
                ev_ctx = tevent_context_init(talloc_autofree_context());
+               tevent_set_debug(ev_ctx, ldb_tevent_debug, ldb);
        }
 
        ret = ldb_setup_wellknown_attributes(ldb);