[PATCH] hostapd: Allow logging to file.
Ben Greear
greearb
Thu Jan 13 10:21:21 PST 2011
Also supports 'relog' CLI command to re-open the
log file.
Signed-off-by: Ben Greear <greearb at candelatech.com>
---
This requires some of my other patches posted previously
to support the 'relog' feature.
:100644 100644 a99ebc0... 684857c... M hostapd/Makefile
:100644 100644 e78fba4... a0a60e0... M hostapd/ctrl_iface.c
:100644 100644 8a87646... c0c4ae7... M hostapd/defconfig
:100644 100644 7cc84bb... 2d3fb5b... M hostapd/hostapd_cli.c
:100644 100644 9c532d4... b5471c2... M hostapd/main.c
hostapd/Makefile | 4 ++++
hostapd/ctrl_iface.c | 9 +++++++++
hostapd/defconfig | 4 ++++
hostapd/hostapd_cli.c | 9 +++++++++
hostapd/main.c | 10 +++++++++-
5 files changed, 35 insertions(+), 1 deletions(-)
diff --git a/hostapd/Makefile b/hostapd/Makefile
index a99ebc0..684857c 100644
--- a/hostapd/Makefile
+++ b/hostapd/Makefile
@@ -740,6 +740,10 @@ ifdef CONFIG_NO_STDOUT_DEBUG
CFLAGS += -DCONFIG_NO_STDOUT_DEBUG
endif
+ifdef CONFIG_DEBUG_FILE
+CFLAGS += -DCONFIG_DEBUG_FILE
+endif
+
ALL=hostapd hostapd_cli
all: verify_config $(ALL)
diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
index e78fba4..a0a60e0 100644
--- a/hostapd/ctrl_iface.c
+++ b/hostapd/ctrl_iface.c
@@ -790,6 +790,15 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
if (os_strcmp(buf, "PING") == 0) {
os_memcpy(reply, "PONG\n", 5);
reply_len = 5;
+#ifdef CONFIG_DEBUG_FILE
+ } else if (os_strncmp(buf, "RELOG", 5) == 0) {
+ if (wpa_debug_reopen_file() < 0) {
+ const char *msg;
+ msg = "ERROR: Failed to reopen log file.\n";
+ reply_len = strlen(msg);
+ os_memcpy(reply, msg, reply_len);
+ }
+#endif
} else if (os_strcmp(buf, "MIB") == 0) {
reply_len = ieee802_11_get_mib(hapd, reply, reply_size);
if (reply_len >= 0) {
diff --git a/hostapd/defconfig b/hostapd/defconfig
index 8a87646..c0c4ae7 100644
--- a/hostapd/defconfig
+++ b/hostapd/defconfig
@@ -144,6 +144,10 @@ CONFIG_IPV6=y
# code is not needed.
#CONFIG_NO_STDOUT_DEBUG=y
+# Add support for writing debug log to a file: -f /tmp/hostapd.log
+# Disabled by default.
+#CONFIG_DEBUG_FILE=y
+
# Remove support for RADIUS accounting
#CONFIG_NO_ACCOUNTING=y
diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
index 7cc84bb..2d3fb5b 100644
--- a/hostapd/hostapd_cli.c
+++ b/hostapd/hostapd_cli.c
@@ -220,6 +220,12 @@ static int hostapd_cli_cmd_ping(struct wpa_ctrl *ctrl, int argc, char *argv[])
return wpa_ctrl_command(ctrl, "PING");
}
+#ifdef CONFIG_DEBUG_FILE
+static int hostapd_cli_cmd_relog(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ return wpa_ctrl_command(ctrl, "RELOG");
+}
+#endif
static int hostapd_cli_cmd_mib(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
@@ -698,6 +704,9 @@ struct hostapd_cli_cmd {
static struct hostapd_cli_cmd hostapd_cli_commands[] = {
{ "ping", hostapd_cli_cmd_ping },
{ "mib", hostapd_cli_cmd_mib },
+#ifdef CONFIG_DEBUG_FILE
+ { "relog", hostapd_cli_cmd_relog },
+#endif
{ "sta", hostapd_cli_cmd_sta },
{ "all_sta", hostapd_cli_cmd_all_sta },
{ "new_sta", hostapd_cli_cmd_new_sta },
diff --git a/hostapd/main.c b/hostapd/main.c
index 9c532d4..b5471c2 100644
--- a/hostapd/main.c
+++ b/hostapd/main.c
@@ -467,6 +467,9 @@ static void usage(void)
" -B run daemon in the background\n"
" -P PID file\n"
" -K include key data in debug messages\n"
+#ifdef CONFIG_DEBUG_FILE
+ " -f = log output to debug file instead of stdout\n"
+#endif /* CONFIG_DEBUG_FILE */
" -t include timestamps in some debug messages\n"
" -v show hostapd version\n");
@@ -486,7 +489,7 @@ int main(int argc, char *argv[])
return -1;
for (;;) {
- c = getopt(argc, argv, "BdhKP:tv");
+ c = getopt(argc, argv, "Bdf:hKP:tv");
if (c < 0)
break;
switch (c) {
@@ -501,6 +504,11 @@ int main(int argc, char *argv[])
case 'B':
daemonize++;
break;
+#ifdef CONFIG_DEBUG_FILE
+ case 'f':
+ wpa_debug_open_file(optarg);
+ break;
+#endif
case 'K':
wpa_debug_show_keys++;
break;
--
1.7.2.3
More information about the Hostap
mailing list