move HISTFILE=$HOME/.ash_history below reading /etc/profile, so that /etc/profile can set $HOME. Home can be unset when directly invoking ash --login from init without going through getty.
This removes also a few lines of code. The lines +setvar("HISTFILE", hp, 0); +free(hp); +hp = lookupvar("HISTFILE"); are added to not leak memory, if this is not important we can remove the last two lines and save a lookupvar. Signed-off-by: Stefan Hellermann <ste...@the2masters.de> diff --git a/shell/ash.c b/shell/ash.c index 0b5111a..7c91a77 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -13191,19 +13191,6 @@ int ash_main(int argc UNUSED_PARAM, char **argv) setstackmark(&smark); procargs(argv); -#if ENABLE_FEATURE_EDITING_SAVEHISTORY - if (iflag) { - const char *hp = lookupvar("HISTFILE"); - if (!hp) { - hp = lookupvar("HOME"); - if (hp) { - char *defhp = concat_path_file(hp, ".ash_history"); - setvar("HISTFILE", defhp, 0); - free(defhp); - } - } - } -#endif if (argv[0] && argv[0][0] == '-') isloginsh = 1; if (isloginsh) { @@ -13243,6 +13230,13 @@ int ash_main(int argc UNUSED_PARAM, char **argv) #if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY if (iflag) { const char *hp = lookupvar("HISTFILE"); + if (!hp) { + hp = lookupvar("HOME"); + hp = concat_path_file(hp, ".ash_history"); + setvar("HISTFILE", hp, 0); + free(hp); + hp = lookupvar("HISTFILE"); + } if (hp) line_input_state->hist_file = hp; # if ENABLE_FEATURE_SH_HISTFILESIZE _______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox