When CONFIG_FEATURE_EDITING_SAVE_ON_EXIT is set to y, the histfile will get 
cleared if the total amount of history lines is less than MAX_HISTORY. 
Only if the histfile is not empty _and_ the amount of lines currently in memory 
are equal to or greater than MAX_HISTORY, history saving will work as expected 
with this feature enabled.

Output from defconfig + CONFIG_FEATURE_EDITING_SAVE_ON_EXIT=y:
[dennis@i7-820qm ~/busybox/a]$ echo "foo" > ~/.ash_history 
[dennis@i7-820qm ~/busybox/a]$ ./busybox ash
~/busybox/a $ echo "bar" > /dev/null
~/busybox/a $ exit
[dennis@i7-820qm ~/busybox/a]$ cat ~/.ash_history 
[dennis@i7-820qm ~/busybox/a]$ 

Attached is a patch that resolves this issue. Output with the patch applied and 
same config as above:
[dennis@i7-820qm ~/busybox/b]$ echo "foo" > ~/.ash_history 
[dennis@i7-820qm ~/busybox/b]$ ./busybox ash
~/busybox/b $ echo "bar" > /dev/null
~/busybox/b $ exit
[dennis@i7-820qm ~/busybox/b]$ cat ~/.ash_history 
foo
echo "bar" > /dev/null
exit
[dennis@i7-820qm ~/busybox/b]$ 

--Dennis

Signed-off-by: Dennis Groenen <tj.groenen at gmail.com>
---
 libbb/lineedit.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index db84167..b89748a 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1352,8 +1352,7 @@ static void load_history(line_input_t *st_parm)
                /* fill temp_h[], retaining only last MAX_HISTORY lines */
                memset(temp_h, 0, sizeof(temp_h));
                idx = 0;
-               if (!ENABLE_FEATURE_EDITING_SAVE_ON_EXIT)
-                       st_parm->cnt_history_in_file = 0;
+               st_parm->cnt_history_in_file = 0;
                while ((line = xmalloc_fgetline(fp)) != NULL) {
                        if (line[0] == '\0') {
                                free(line);
@@ -1361,8 +1360,7 @@ static void load_history(line_input_t *st_parm)
                        }
                        free(temp_h[idx]);
                        temp_h[idx] = line;
-                       if (!ENABLE_FEATURE_EDITING_SAVE_ON_EXIT)
-                               st_parm->cnt_history_in_file++;
+                       st_parm->cnt_history_in_file++;
                        idx++;
                        if (idx == st_parm->max_history)
                                idx = 0;
-- 
1.7.10


_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to