[PATCH] wpa_supplicant: Support 'relog' command to re-open log files.

Ben Greear greearb
Mon Nov 29 11:41:56 PST 2010


This allows rolling log files:

mv log.txt log.txt.1
wpa_cli relog

Signed-off-by: Ben Greear <greearb at candelatech.com>
---
:100644 100644 6f6fc69... fb7811d... M	src/utils/wpa_debug.c
:100644 100644 f2e8646... fb59ea5... M	src/utils/wpa_debug.h
:100644 100644 2a635dd... db99351... M	wpa_supplicant/ctrl_iface.c
:100644 100644 2e2d3ab... 3577c68... M	wpa_supplicant/wpa_cli.c
 src/utils/wpa_debug.c       |   25 +++++++++++++++++++++++++
 src/utils/wpa_debug.h       |    1 +
 wpa_supplicant/ctrl_iface.c |    6 ++++++
 wpa_supplicant/wpa_cli.c    |    8 ++++++++
 4 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/src/utils/wpa_debug.c b/src/utils/wpa_debug.c
index 6f6fc69..fb7811d 100644
--- a/src/utils/wpa_debug.c
+++ b/src/utils/wpa_debug.c
@@ -272,12 +272,37 @@ void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
 	_wpa_hexdump_ascii(level, title, buf, len, wpa_debug_show_keys);
 }
 
+static char* last_path;
+
+int wpa_debug_reopen_file(void)
+{
+	int rv;
+	if (last_path) {
+		char* tmp = strdup(last_path);
+		wpa_debug_close_file();
+		rv = wpa_debug_open_file(tmp);
+		free(tmp);
+	}
+	else {
+		wpa_printf(MSG_ERROR, "Last-path was not set, cannot"
+			   " re-open log file.\n");
+		rv = -1;
+	}
+	return rv;
+}
+	
 
 int wpa_debug_open_file(const char *path)
 {
 #ifdef CONFIG_DEBUG_FILE
 	if (!path)
 		return 0;
+
+	/* Save our path to enable re-open */
+	if (last_path)
+		free(last_path);
+	last_path = strdup(path);
+	
 	out_file = fopen(path, "a");
 	if (out_file == NULL) {
 		wpa_printf(MSG_ERROR, "wpa_debug_open_file: Failed to open "
diff --git a/src/utils/wpa_debug.h b/src/utils/wpa_debug.h
index f2e8646..fb59ea5 100644
--- a/src/utils/wpa_debug.h
+++ b/src/utils/wpa_debug.h
@@ -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);
 
 /**
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 2a635dd..db99351 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -2787,6 +2787,12 @@ 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) {
+			const char* msg = "ERROR:  Failed to reopen log file.\n";
+			reply_len = strlen(msg);
+			os_memcpy(reply, msg, reply_len);
+		}
 	} else if (os_strncmp(buf, "NOTE ", 5) == 0) {
 		wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
 	} else if (os_strcmp(buf, "MIB") == 0) {
diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index 2e2d3ab..3577c68 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -277,6 +277,11 @@ static int wpa_cli_cmd_ping(struct wpa_ctrl *ctrl, int argc, char *argv[])
 	return wpa_ctrl_command(ctrl, "PING");
 }
 
+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[])
 {
@@ -2164,6 +2169,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" },
-- 
1.7.2.3




More information about the Hostap mailing list