aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDennis Groenen <tj.groenen@gmail.com>2012-04-24 22:40:58 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2012-04-26 11:19:38 +0200
commitdeee356a629c81aae64ac22266561e9cc4e13e8b (patch)
treed6d122ba2d5d8650ee31dc74e483fe0fc13a3b63 /libbb
parent9d75370238314746986760a3cc279252d152db36 (diff)
downloadbusybox-w32-deee356a629c81aae64ac22266561e9cc4e13e8b.tar.gz
busybox-w32-deee356a629c81aae64ac22266561e9cc4e13e8b.tar.bz2
busybox-w32-deee356a629c81aae64ac22266561e9cc4e13e8b.zip
lineedit: histfile can get emptied when CONFIG_FEATURE_EDITING_SAVE_ON_EXIT=y
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: $ echo "foo" > ~/.ash_history $ ./busybox ash ~/busybox/a $ echo "bar" > /dev/null ~/busybox/a $ exit $ cat ~/.ash_history $ Output with the patch applied and same config as above: $ echo "foo" > ~/.ash_history $ ./busybox ash ~/busybox/b $ echo "bar" > /dev/null ~/busybox/b $ exit $ cat ~/.ash_history foo echo "bar" > /dev/null exit $ Signed-off-by: Dennis Groenen <tj.groenen at gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/lineedit.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index db8416712..b89748a1c 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1352,8 +1352,7 @@ static void load_history(line_input_t *st_parm)
1352 /* fill temp_h[], retaining only last MAX_HISTORY lines */ 1352 /* fill temp_h[], retaining only last MAX_HISTORY lines */
1353 memset(temp_h, 0, sizeof(temp_h)); 1353 memset(temp_h, 0, sizeof(temp_h));
1354 idx = 0; 1354 idx = 0;
1355 if (!ENABLE_FEATURE_EDITING_SAVE_ON_EXIT) 1355 st_parm->cnt_history_in_file = 0;
1356 st_parm->cnt_history_in_file = 0;
1357 while ((line = xmalloc_fgetline(fp)) != NULL) { 1356 while ((line = xmalloc_fgetline(fp)) != NULL) {
1358 if (line[0] == '\0') { 1357 if (line[0] == '\0') {
1359 free(line); 1358 free(line);
@@ -1361,8 +1360,7 @@ static void load_history(line_input_t *st_parm)
1361 } 1360 }
1362 free(temp_h[idx]); 1361 free(temp_h[idx]);
1363 temp_h[idx] = line; 1362 temp_h[idx] = line;
1364 if (!ENABLE_FEATURE_EDITING_SAVE_ON_EXIT) 1363 st_parm->cnt_history_in_file++;
1365 st_parm->cnt_history_in_file++;
1366 idx++; 1364 idx++;
1367 if (idx == st_parm->max_history) 1365 if (idx == st_parm->max_history)
1368 idx = 0; 1366 idx = 0;