lib/util: allow samba_tevent_debug() to take a name as context
authorStefan Metzmacher <metze@samba.org>
Thu, 21 Feb 2013 07:23:42 +0000 (08:23 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 28 Feb 2013 11:10:05 +0000 (12:10 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
lib/util/tevent_debug.c

index 3a5a3132f99815e39a1b3874bcb14bf92161593a..6df58aeaf0129686876b1a694a3fcc4ff20a4aa7 100644 (file)
@@ -30,7 +30,7 @@ static void samba_tevent_debug(void *context,
                               va_list ap)
 {
        int samba_level = -1;
-       char *s = NULL;
+
        switch (level) {
        case TEVENT_DEBUG_FATAL:
                samba_level = 0;
@@ -47,10 +47,21 @@ static void samba_tevent_debug(void *context,
        };
 
        if (CHECK_DEBUGLVL(samba_level)) {
-               vasprintf(&s, fmt, ap);
-               if (!s) return;
-               DEBUG(samba_level, ("samba_tevent: %s", s));
-               free(s);
+               const char *name = (const char *)context;
+               char *message = NULL;
+               int ret;
+
+               ret = vasprintf(&message, fmt, ap);
+               if (ret == -1) {
+                       return;
+               }
+
+               if (name == NULL) {
+                       name = "samba_tevent";
+               }
+
+               DEBUG(samba_level, ("%s: %s", name, message));
+               free(message);
        }
 }