]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wpa_supplicant: Support 'relog' command to re-open log files
authorBen Greear <greearb@candelatech.com>
Sun, 6 Feb 2011 18:15:19 +0000 (20:15 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 6 Feb 2011 18:15:19 +0000 (20:15 +0200)
This allows rolling log files:

mv log.txt log.txt.1
wpa_cli relog

Signed-off-by: Ben Greear <greearb@candelatech.com>
src/utils/wpa_debug.c
src/utils/wpa_debug.h
wpa_supplicant/ctrl_iface.c
wpa_supplicant/wpa_cli.c

index 6f6fc69ccc44a935280c2e89acd61c93ff92cec3..560b85a84873184fcacf2cf5413a036a1ae78bf2 100644 (file)
@@ -273,11 +273,43 @@ void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
 }
 
 
+#ifdef CONFIG_DEBUG_FILE
+static char *last_path = NULL;
+#endif /* CONFIG_DEBUG_FILE */
+
+int wpa_debug_reopen_file(void)
+{
+#ifdef CONFIG_DEBUG_FILE
+       int rv;
+       if (last_path) {
+               char *tmp = os_strdup(last_path);
+               wpa_debug_close_file();
+               rv = wpa_debug_open_file(tmp);
+               os_free(tmp);
+       } else {
+               wpa_printf(MSG_ERROR, "Last-path was not set, cannot "
+                          "re-open log file.");
+               rv = -1;
+       }
+       return rv;
+#else /* CONFIG_DEBUG_FILE */
+       return 0;
+#endif /* CONFIG_DEBUG_FILE */
+}
+
+
 int wpa_debug_open_file(const char *path)
 {
 #ifdef CONFIG_DEBUG_FILE
        if (!path)
                return 0;
+
+       if (last_path == NULL || os_strcmp(last_path, path) != 0) {
+               /* Save our path to enable re-open */
+               os_free(last_path);
+               last_path = os_strdup(path);
+       }
+
        out_file = fopen(path, "a");
        if (out_file == NULL) {
                wpa_printf(MSG_ERROR, "wpa_debug_open_file: Failed to open "
@@ -299,6 +331,8 @@ void wpa_debug_close_file(void)
                return;
        fclose(out_file);
        out_file = NULL;
+       os_free(last_path);
+       last_path = NULL;
 #endif /* CONFIG_DEBUG_FILE */
 }
 
index f2e86460c115a3264910bda47ee8d37fca561694..fb59ea5404ee0f91719ff1558fbb70b0cb322964 100644 (file)
@@ -40,6 +40,7 @@ enum {
 #else /* CONFIG_NO_STDOUT_DEBUG */
 
 int wpa_debug_open_file(const char *path);
+int wpa_debug_reopen_file(void);
 void wpa_debug_close_file(void);
 
 /**
index 38aadd50a4cb466ef792e97b4ae5e20c11b3e088..7731895f4082750401745ec56337283eb80f33a0 100644 (file)
@@ -2785,6 +2785,9 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
        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_strncmp(buf, "NOTE ", 5) == 0) {
                wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
        } else if (os_strcmp(buf, "MIB") == 0) {
index be62fb0e13acc81178eefd6310a66ba801b50387..c511cc064a6528d0a543555512324f318358fb18 100644 (file)
@@ -278,6 +278,12 @@ static int wpa_cli_cmd_ping(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+static int wpa_cli_cmd_relog(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+       return wpa_ctrl_command(ctrl, "RELOG");
+}
+
+
 static int wpa_cli_cmd_note(struct wpa_ctrl *ctrl, int argc, char *argv[])
 {
        char cmd[256];
@@ -2164,6 +2170,9 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
        { "ping", wpa_cli_cmd_ping,
          cli_cmd_flag_none,
          "= pings wpa_supplicant" },
+       { "relog", wpa_cli_cmd_relog,
+         cli_cmd_flag_none,
+         "= re-open log-file (allow rolling logs)" },
        { "note", wpa_cli_cmd_note,
          cli_cmd_flag_none,
          "<text> = add a note to wpa_supplicant debug log" },