From b41a47c03f7d94c70a2b9e0397947ef01cd3c552 Mon Sep 17 00:00:00 2001 From: Ben Greear Date: Sun, 6 Feb 2011 20:24:16 +0200 Subject: [PATCH] hostapd: Allow logging to file Also supports 'relog' CLI command to re-open the log file. Signed-off-by: Ben Greear --- hostapd/Makefile | 4 ++++ hostapd/ctrl_iface.c | 3 +++ hostapd/defconfig | 4 ++++ hostapd/hostapd_cli.c | 7 +++++++ hostapd/main.c | 15 ++++++++++++++- 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/hostapd/Makefile b/hostapd/Makefile index c4ccedf76..47188c2cc 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 e78fba42e..d3ab6242a 100644 --- a/hostapd/ctrl_iface.c +++ b/hostapd/ctrl_iface.c @@ -790,6 +790,9 @@ 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; + } else if (os_strncmp(buf, "RELOG", 5) == 0) { + if (wpa_debug_reopen_file() < 0) + reply_len = -1; } 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 8a87646b2..c0c4ae766 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 7cc84bb98..618ec2629 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -221,6 +221,12 @@ static int hostapd_cli_cmd_ping(struct wpa_ctrl *ctrl, int argc, char *argv[]) } +static int hostapd_cli_cmd_relog(struct wpa_ctrl *ctrl, int argc, char *argv[]) +{ + return wpa_ctrl_command(ctrl, "RELOG"); +} + + static int hostapd_cli_cmd_mib(struct wpa_ctrl *ctrl, int argc, char *argv[]) { return wpa_ctrl_command(ctrl, "MIB"); @@ -698,6 +704,7 @@ struct hostapd_cli_cmd { static struct hostapd_cli_cmd hostapd_cli_commands[] = { { "ping", hostapd_cli_cmd_ping }, { "mib", hostapd_cli_cmd_mib }, + { "relog", hostapd_cli_cmd_relog }, { "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 9c532d4cc..45836df8d 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"); @@ -481,12 +484,13 @@ int main(int argc, char *argv[]) size_t i; int c, debug = 0, daemonize = 0; char *pid_file = NULL; + const char *log_file = NULL; if (os_program_init()) return -1; for (;;) { - c = getopt(argc, argv, "BdhKP:tv"); + c = getopt(argc, argv, "Bdf:hKP:tv"); if (c < 0) break; switch (c) { @@ -501,6 +505,9 @@ int main(int argc, char *argv[]) case 'B': daemonize++; break; + case 'f': + log_file = optarg; + break; case 'K': wpa_debug_show_keys++; break; @@ -525,6 +532,9 @@ int main(int argc, char *argv[]) if (optind == argc) usage(); + if (log_file) + wpa_debug_open_file(log_file); + interfaces.count = argc - optind; interfaces.iface = os_malloc(interfaces.count * sizeof(struct hostapd_iface *)); @@ -559,6 +569,9 @@ int main(int argc, char *argv[]) hostapd_global_deinit(pid_file); os_free(pid_file); + if (log_file) + wpa_debug_close_file(); + os_program_deinit(); return ret;