aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBen Greear <greearb@candelatech.com>2011-02-06 18:39:34 (GMT)
committerJouni Malinen <j@w1.fi>2011-02-06 18:39:34 (GMT)
commit4f1495aefa1e5d5b4230229c9619c7d4923a2676 (patch)
tree8f6933ee3ad6350bf03e704ce313b3c2bd90ada2 /src
parentb41a47c03f7d94c70a2b9e0397947ef01cd3c552 (diff)
downloadhostap-4f1495aefa1e5d5b4230229c9619c7d4923a2676.zip
hostap-4f1495aefa1e5d5b4230229c9619c7d4923a2676.tar.gz
hostap-4f1495aefa1e5d5b4230229c9619c7d4923a2676.tar.bz2
Add interface name to wpa_msg() output
This makes log files much more readable if multiple interfaces are being controlled by the same process. The interface name is added to stdout/file/syslog entries, but not to the messages sent to control interface monitors to avoid issues with parsing in external programs. Signed-off-by: Ben Greear <greearb@candelatech.com>
Diffstat (limited to 'src')
-rw-r--r--src/utils/wpa_debug.c21
-rw-r--r--src/utils/wpa_debug.h5
2 files changed, 24 insertions, 2 deletions
diff --git a/src/utils/wpa_debug.c b/src/utils/wpa_debug.c
index 560b85a..fa453eb 100644
--- a/src/utils/wpa_debug.c
+++ b/src/utils/wpa_debug.c
@@ -348,12 +348,21 @@ void wpa_msg_register_cb(wpa_msg_cb_func func)
}
+static wpa_msg_get_ifname_func wpa_msg_ifname_cb = NULL;
+
+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;
+ char prefix[130];
buf = os_malloc(buflen);
if (buf == NULL) {
@@ -362,9 +371,19 @@ void wpa_msg(void *ctx, int level, const char *fmt, ...)
return;
}
va_start(ap, fmt);
+ prefix[0] = '\0';
+ if (wpa_msg_ifname_cb) {
+ const char *ifname = wpa_msg_ifname_cb(ctx);
+ if (ifname) {
+ int res = os_snprintf(prefix, sizeof(prefix), "%s: ",
+ ifname);
+ if (res < 0 || res >= (int) sizeof(prefix))
+ prefix[0] = '\0';
+ }
+ }
len = vsnprintf(buf, buflen, fmt, ap);
va_end(ap);
- wpa_printf(level, "%s", buf);
+ wpa_printf(level, "%s%s", prefix, buf);
if (wpa_msg_cb)
wpa_msg_cb(ctx, level, buf, len);
os_free(buf);
diff --git a/src/utils/wpa_debug.h b/src/utils/wpa_debug.h
index fb59ea5..ee258ff 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)