]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
hostapd: Allow logging to file
authorBen Greear <greearb@candelatech.com>
Sun, 6 Feb 2011 18:24:16 +0000 (20:24 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 6 Feb 2011 18:24:16 +0000 (20:24 +0200)
Also supports 'relog' CLI command to re-open the log file.

Signed-off-by: Ben Greear <greearb@candelatech.com>
hostapd/Makefile
hostapd/ctrl_iface.c
hostapd/defconfig
hostapd/hostapd_cli.c
hostapd/main.c

index c4ccedf76bd89e053de81c9e6a144c9cd1aee6a3..47188c2ccb5438ad499442367466d16822894d40 100644 (file)
@@ -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)
index e78fba42e0d0177c05615651e6efa0c81214f90e..d3ab6242af6555ff0c67193dd67367dafff84bdd 100644 (file)
@@ -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) {
index 8a87646b2e124a70dfa47a5fbf929be8d7e5538a..c0c4ae76692fd1b3847124afed334084513b565c 100644 (file)
@@ -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
 
index 7cc84bb98f7dfffd3b2de703714cdbdef5d351d0..618ec2629f428b0cf6334451a6a77168f53a40cb 100644 (file)
@@ -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 },
index 9c532d4cce6e3d42bf2d80edd706ba4224dd3e0d..45836df8dc37a9282c9cc1aca604e2a057a5da1c 100644 (file)
@@ -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;