[PATCH] hostap: Add vif name to wpa_msg output.
Ben Greear
greearb
Fri Dec 3 11:09:19 PST 2010
This makes log files much more readable.
Signed-off-by: Ben Greear <greearb at candelatech.com>
---
:100644 100644 fb7811d... 1c32cb5... M src/utils/wpa_debug.c
:100644 100644 fb59ea5... bc1815f... M src/utils/wpa_debug.h
:100644 100644 7a9001d... 7b74d23... M wpa_supplicant/wpa_supplicant.c
src/utils/wpa_debug.c | 12 ++++++++++--
src/utils/wpa_debug.h | 5 ++++-
wpa_supplicant/wpa_supplicant.c | 10 ++++++++++
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/src/utils/wpa_debug.c b/src/utils/wpa_debug.c
index fb7811d..1c32cb5 100644
--- a/src/utils/wpa_debug.c
+++ b/src/utils/wpa_debug.c
@@ -338,13 +338,19 @@ void wpa_msg_register_cb(wpa_msg_cb_func func)
wpa_msg_cb = func;
}
+static wpa_msg_get_ifname_func wpa_msg_ifname_cb;
+
+void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func)
+{
+ wpa_msg_ifname_cb = func;
+}
void wpa_msg(void *ctx, int level, const char *fmt, ...)
{
va_list ap;
char *buf;
const int buflen = 2048;
- int len;
+ int len = 0;
buf = os_malloc(buflen);
if (buf == NULL) {
@@ -353,7 +359,9 @@ void wpa_msg(void *ctx, int level, const char *fmt, ...)
return;
}
va_start(ap, fmt);
- len = vsnprintf(buf, buflen, fmt, ap);
+ if (wpa_msg_ifname_cb)
+ len = snprintf(buf, buflen, "%s: ", wpa_msg_ifname_cb(ctx));
+ len = vsnprintf(buf + len, buflen - len, fmt, ap);
va_end(ap);
wpa_printf(level, "%s", buf);
if (wpa_msg_cb)
diff --git a/src/utils/wpa_debug.h b/src/utils/wpa_debug.h
index fb59ea5..bc1815f 100644
--- a/src/utils/wpa_debug.h
+++ b/src/utils/wpa_debug.h
@@ -188,8 +188,11 @@ typedef void (*wpa_msg_cb_func)(void *ctx, int level, const char *txt,
* @func: Callback function (%NULL to unregister)
*/
void wpa_msg_register_cb(wpa_msg_cb_func func);
-#endif /* CONFIG_NO_WPA_MSG */
+typedef const char* (*wpa_msg_get_ifname_func)(void *ctx);
+void wpa_msg_register_ifname_cb(wpa_msg_get_ifname_func func);
+
+#endif /* CONFIG_NO_WPA_MSG */
#ifdef CONFIG_NO_HOSTAPD_LOGGER
#define hostapd_logger(args...) do { } while (0)
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 7a9001d..7b74d23 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -2333,6 +2333,14 @@ struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global,
return NULL;
}
+static const char *wpa_supplicant_msg_ifname_cb(void *ctx)
+{
+ struct wpa_supplicant *wpa_s = ctx;
+ if (wpa_s == NULL)
+ return "NULL";
+ return wpa_s->ifname;
+}
+
/**
* wpa_supplicant_init - Initialize %wpa_supplicant
@@ -2355,6 +2363,8 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
if (params->wpa_debug_syslog)
wpa_debug_open_syslog();
+ wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb);
+
ret = eap_register_methods();
if (ret) {
wpa_printf(MSG_ERROR, "Failed to register EAP methods");
--
1.7.2.3
More information about the Hostap
mailing list