Message ID | 20220521060348.31239-1-me@gyara.moe |
---|---|
State | Changes Requested |
Headers | show |
Series | Move wpa_cli_history default to $XDG_DATA_HOME and fallback to $HOME | expand |
On Sat, May 21, 2022 at 03:03:49PM +0900, gyara wrote: > --- > This patch try use $XDG_DATA_HOME/.wpa_cli_history as wpa cli hist file > path prefer than $HOME/.wpa_cli_history. Why? This patch would also need to come with the Signed-off-by: line as described in the top level CONTRIBUTIONS file for me to be able to consider applying it. > static void start_edit(void) > { > - char *home; > + char *hist_home; That seems unnecessary. > @@ -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; This is unnecessary complexity.. > #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"); > + } home = getenv("XDG_DATA_HOME"); if (!home) home = getenv("HOME") would be a much simpler way of doing all of this..
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,