[PATCH] Move wpa_cli_history default to $XDG_DATA_HOME and fallback to $HOME

gyara me at gyara.moe
Fri May 20 23:03:49 PDT 2022


---
This patch try use $XDG_DATA_HOME/.wpa_cli_history as wpa cli hist file
path prefer than $HOME/.wpa_cli_history.

 wpa_supplicant/wpa_cli.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index 0e2315d..5ac5b69 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -4636,7 +4636,7 @@ static int edit_started = 0;
 
 static void start_edit(void)
 {
-	char *home;
+	char *hist_home;
 	char *ps = NULL;
 
 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
@@ -4644,16 +4644,21 @@ static void start_edit(void)
 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
 
 #ifdef CONFIG_WPA_CLI_HISTORY_DIR
-	home = CONFIG_WPA_CLI_HISTORY_DIR;
+	hist_home = CONFIG_WPA_CLI_HISTORY_DIR;
 #else /* CONFIG_WPA_CLI_HISTORY_DIR */
-	home = getenv("HOME");
+	char* xdg_data_home = getenv("XDG_DATA_HOME");
+	if (xdg_data_home) {
+		hist_home = xdg_data_home;
+	} else {
+		hist_home = getenv("HOME");
+	}
 #endif /* CONFIG_WPA_CLI_HISTORY_DIR */
-	if (home) {
+	if (hist_home) {
 		const char *fname = ".wpa_cli_history";
-		int hfile_len = os_strlen(home) + 1 + os_strlen(fname) + 1;
+		int hfile_len = os_strlen(hist_home) + 1 + os_strlen(fname) + 1;
 		hfile = os_malloc(hfile_len);
 		if (hfile)
-			os_snprintf(hfile, hfile_len, "%s/%s", home, fname);
+			os_snprintf(hfile, hfile_len, "%s/%s", hist_home, fname);
 	}
 
 	if (edit_init(wpa_cli_edit_cmd_cb, wpa_cli_edit_eof_cb,
-- 
2.36.1




More information about the Hostap mailing list