diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-04 15:28:03 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-09-04 15:28:03 +0200 |
| commit | 4840ae8a06298e987374fa3cc6d7e4969fd19344 (patch) | |
| tree | 53fd9b0ffe5eb4a8798aa3fd6a3c1299c7357dc0 | |
| parent | 7b46220d922d7c6267a8442ff8c3a6d1ab106727 (diff) | |
| download | busybox-w32-4840ae8a06298e987374fa3cc6d7e4969fd19344.tar.gz busybox-w32-4840ae8a06298e987374fa3cc6d7e4969fd19344.tar.bz2 busybox-w32-4840ae8a06298e987374fa3cc6d7e4969fd19344.zip | |
lineedit: fix atomic replace of history file; hush: fix $HISTFILE handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | libbb/lineedit.c | 4 | ||||
| -rw-r--r-- | shell/ash.c | 2 | ||||
| -rw-r--r-- | shell/hush.c | 40 |
3 files changed, 26 insertions, 20 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 10265192e..5d139043a 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
| @@ -1425,7 +1425,7 @@ static void save_history(char *str) | |||
| 1425 | 1425 | ||
| 1426 | /* write out temp file and replace hist_file atomically */ | 1426 | /* write out temp file and replace hist_file atomically */ |
| 1427 | new_name = xasprintf("%s.%u.new", state->hist_file, (int) getpid()); | 1427 | new_name = xasprintf("%s.%u.new", state->hist_file, (int) getpid()); |
| 1428 | fd = open(state->hist_file, O_WRONLY | O_CREAT | O_TRUNC, 0600); | 1428 | fd = open(new_name, O_WRONLY | O_CREAT | O_TRUNC, 0600); |
| 1429 | if (fd >= 0) { | 1429 | if (fd >= 0) { |
| 1430 | FILE *fp; | 1430 | FILE *fp; |
| 1431 | int i; | 1431 | int i; |
| @@ -1475,7 +1475,7 @@ static void remember_in_history(char *str) | |||
| 1475 | /* i <= state->max_history */ | 1475 | /* i <= state->max_history */ |
| 1476 | state->cur_history = i; | 1476 | state->cur_history = i; |
| 1477 | state->cnt_history = i; | 1477 | state->cnt_history = i; |
| 1478 | # if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY | 1478 | # if ENABLE_FEATURE_EDITING_SAVEHISTORY |
| 1479 | if ((state->flags & SAVE_HISTORY) && state->hist_file) | 1479 | if ((state->flags & SAVE_HISTORY) && state->hist_file) |
| 1480 | save_history(str); | 1480 | save_history(str); |
| 1481 | # endif | 1481 | # endif |
diff --git a/shell/ash.c b/shell/ash.c index d48cd016f..bf376bd0d 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
| @@ -13194,7 +13194,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
| 13194 | } | 13194 | } |
| 13195 | 13195 | ||
| 13196 | if (sflag || minusc == NULL) { | 13196 | if (sflag || minusc == NULL) { |
| 13197 | #if defined MAX_HISTORY && MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY | 13197 | #if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY |
| 13198 | if (iflag) { | 13198 | if (iflag) { |
| 13199 | const char *hp = lookupvar("HISTFILE"); | 13199 | const char *hp = lookupvar("HISTFILE"); |
| 13200 | if (hp) | 13200 | if (hp) |
diff --git a/shell/hush.c b/shell/hush.c index e4138adf7..42143fd9e 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
| @@ -7816,23 +7816,7 @@ int hush_main(int argc, char **argv) | |||
| 7816 | */ | 7816 | */ |
| 7817 | 7817 | ||
| 7818 | #if ENABLE_FEATURE_EDITING | 7818 | #if ENABLE_FEATURE_EDITING |
| 7819 | G.line_input_state = new_line_input_t(FOR_SHELL); | 7819 | G.line_input_state = new_line_input_t(FOR_SHELL & ~SAVE_HISTORY); |
| 7820 | # if defined MAX_HISTORY && MAX_HISTORY > 0 && ENABLE_HUSH_SAVEHISTORY | ||
| 7821 | { | ||
| 7822 | const char *hp = get_local_var_value("HISTFILE"); | ||
| 7823 | if (!hp) { | ||
| 7824 | hp = get_local_var_value("HOME"); | ||
| 7825 | if (hp) { | ||
| 7826 | G.line_input_state->hist_file = concat_path_file(hp, ".hush_history"); | ||
| 7827 | //set_local_var(xasprintf("HISTFILE=%s", ...)); | ||
| 7828 | } | ||
| 7829 | } | ||
| 7830 | # if ENABLE_FEATURE_SH_HISTFILESIZE | ||
| 7831 | hp = get_local_var_value("HISTFILESIZE"); | ||
| 7832 | G.line_input_state->max_history = size_from_HISTFILESIZE(hp); | ||
| 7833 | # endif | ||
| 7834 | } | ||
| 7835 | # endif | ||
| 7836 | #endif | 7820 | #endif |
| 7837 | 7821 | ||
| 7838 | /* Initialize some more globals to non-zero values */ | 7822 | /* Initialize some more globals to non-zero values */ |
| @@ -8104,6 +8088,28 @@ int hush_main(int argc, char **argv) | |||
| 8104 | /* -1 is special - makes xfuncs longjmp, not exit | 8088 | /* -1 is special - makes xfuncs longjmp, not exit |
| 8105 | * (we reset die_sleep = 0 whereever we [v]fork) */ | 8089 | * (we reset die_sleep = 0 whereever we [v]fork) */ |
| 8106 | enable_restore_tty_pgrp_on_exit(); /* sets die_sleep = -1 */ | 8090 | enable_restore_tty_pgrp_on_exit(); /* sets die_sleep = -1 */ |
| 8091 | |||
| 8092 | # if ENABLE_HUSH_SAVEHISTORY && MAX_HISTORY > 0 | ||
| 8093 | { | ||
| 8094 | const char *hp = get_local_var_value("HISTFILE"); | ||
| 8095 | if (!hp) { | ||
| 8096 | hp = get_local_var_value("HOME"); | ||
| 8097 | if (hp) | ||
| 8098 | hp = concat_path_file(hp, ".hush_history"); | ||
| 8099 | } else { | ||
| 8100 | hp = xstrdup(hp); | ||
| 8101 | } | ||
| 8102 | if (hp) { | ||
| 8103 | G.line_input_state->hist_file = hp; | ||
| 8104 | G.line_input_state->flags |= SAVE_HISTORY; | ||
| 8105 | //set_local_var(xasprintf("HISTFILE=%s", ...)); | ||
| 8106 | } | ||
| 8107 | # if ENABLE_FEATURE_SH_HISTFILESIZE | ||
| 8108 | hp = get_local_var_value("HISTFILESIZE"); | ||
| 8109 | G.line_input_state->max_history = size_from_HISTFILESIZE(hp); | ||
| 8110 | # endif | ||
| 8111 | } | ||
| 8112 | # endif | ||
| 8107 | } else { | 8113 | } else { |
| 8108 | install_special_sighandlers(); | 8114 | install_special_sighandlers(); |
| 8109 | } | 8115 | } |
