synchronize history patches with busybox git
authorDennis Groenen <tj.groenen@gmail.com>
Sat, 10 Sep 2011 13:14:51 +0000 (15:14 +0200)
committerDennis Groenen <tj.groenen@gmail.com>
Sat, 10 Sep 2011 13:14:51 +0000 (15:14 +0200)
debian/config/config.busybox
debian/patches/0001-add-support-for-delayed-history-saving.patch [deleted file]
debian/patches/0001-lineedit-fix-history-saving-when-history-MAX_HISTORY.patch [new file with mode: 0644]
debian/patches/0002-hush-don-t-save-history-when-non-interactive.patch [deleted file]
debian/patches/git-backports/0001-lineedit-fix-atomic-replace-of-history-file-hush-fix.patch [new file with mode: 0644]
debian/patches/git-backports/0002-lineedit-add-support-for-history-saving-on-exit.patch [new file with mode: 0644]
debian/patches/git-backports/0003-lineedit-remove-SAVE_HISTORY-bit-hist_file-can-be-us.patch [new file with mode: 0644]
debian/patches/series

index 0c09289..d1a70cb 100644 (file)
@@ -101,7 +101,7 @@ CONFIG_FEATURE_EDITING_MAX_LEN=1024
 # CONFIG_FEATURE_EDITING_VI is not set
 CONFIG_FEATURE_EDITING_HISTORY=100
 CONFIG_FEATURE_EDITING_SAVEHISTORY=y
-CONFIG_FEATURE_EDITING_DELAYEDHISTORY=y
+CONFIG_FEATURE_EDITING_SAVE_ON_EXIT=y
 CONFIG_FEATURE_REVERSE_SEARCH=y
 CONFIG_FEATURE_TAB_COMPLETION=y
 # CONFIG_FEATURE_USERNAME_COMPLETION is not set
diff --git a/debian/patches/0001-add-support-for-delayed-history-saving.patch b/debian/patches/0001-add-support-for-delayed-history-saving.patch
deleted file mode 100644 (file)
index ce9e112..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-From 772cc01d3739d50ae43858fed8ec733c0c7bf00c Mon Sep 17 00:00:00 2001
-From: Dennis Groenen <tj.groenen@gmail.com>
-Date: Sun, 21 Aug 2011 13:28:34 +0200
-Subject: [PATCH] add support for delayed history saving
-
----
- include/libbb.h  |    3 +++
- libbb/Config.src |    8 ++++++++
- libbb/lineedit.c |   24 +++++++++++++++++++++++-
- shell/ash.c      |    5 +++++
- shell/hush.c     |    5 +++++
- 5 files changed, 44 insertions(+), 1 deletions(-)
-
-diff --git a/include/libbb.h b/include/libbb.h
-index 63d0419..233b674 100644
---- a/include/libbb.h
-+++ b/include/libbb.h
-@@ -1446,6 +1446,9 @@ line_input_t *new_line_input_t(int flags) FAST_FUNC;
-  * >0 length of input string, including terminating '\n'
-  */
- int read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) FAST_FUNC;
-+# if ENABLE_FEATURE_EDITING_DELAYEDHISTORY
-+void save_history(line_input_t *st);
-+# endif
- #else
- #define MAX_HISTORY 0
- int read_line_input(const char* prompt, char* command, int maxsize) FAST_FUNC;
-diff --git a/libbb/Config.src b/libbb/Config.src
-index aa44236..deee15f 100644
---- a/libbb/Config.src
-+++ b/libbb/Config.src
-@@ -94,6 +94,14 @@ config FEATURE_EDITING_SAVEHISTORY
-       help
-         Enable history saving in shells.
-+config FEATURE_EDITING_DELAYEDHISTORY
-+      bool "Delayed history saving"
-+      default n
-+      depends on FEATURE_EDITING_SAVEHISTORY
-+      help
-+        Disable saving history to disk after every command. Write out
-+        history only upon shell closure instead.
-+
- config FEATURE_REVERSE_SEARCH
-       bool "Reverse history search"
-       default y
-diff --git a/libbb/lineedit.c b/libbb/lineedit.c
-index 1026519..48ac509 100644
---- a/libbb/lineedit.c
-+++ b/libbb/lineedit.c
-@@ -1392,10 +1392,29 @@ static void load_history(line_input_t *st_parm)
-       }
- }
--/* state->flags is already checked to be nonzero */
-+# if ENABLE_FEATURE_EDITING_DELAYEDHISTORY
-+void save_history(line_input_t *st)
-+# else
- static void save_history(char *str)
-+# endif
- {
-       int fd;
-+# if ENABLE_FEATURE_EDITING_DELAYEDHISTORY
-+#  if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
-+      FILE *f_hist_file;
-+      state = st ? st : (line_input_t*) &const_int_0;
-+      f_hist_file = fopen(state->hist_file,"a");
-+      if (f_hist_file) {
-+              int i;
-+              for (i = state->cnt_history_in_file; i < state->cnt_history; i++)
-+                      fprintf(f_hist_file, "%s\n", state->history[i]);
-+      }
-+      fclose(f_hist_file);
-+#  else
-+      return;
-+#  endif
-+# else
-+      /* state->flags is already checked to be nonzero */
-       int len, len2;
-       fd = open(state->hist_file, O_WRONLY | O_CREAT | O_APPEND, 0600);
-@@ -1409,6 +1428,7 @@ static void save_history(char *str)
-       close(fd);
-       if (len2 != len + 1)
-               return; /* "wtf?" */
-+# endif /* FEATURE_EDITING_DELAYEDHISTORY */
-       /* did we write so much that history file needs trimming? */
-       state->cnt_history_in_file++;
-@@ -1475,10 +1495,12 @@ static void remember_in_history(char *str)
-       /* i <= state->max_history */
-       state->cur_history = i;
-       state->cnt_history = i;
-+#if !ENABLE_FEATURE_EDITING_DELAYEDHISTORY /* save_history() will be called by exit_shell() */
- # if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
-       if ((state->flags & SAVE_HISTORY) && state->hist_file)
-               save_history(str);
- # endif
-+#endif
-       IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;)
- }
-diff --git a/shell/ash.c b/shell/ash.c
-index d48cd01..08d4e92 100644
---- a/shell/ash.c
-+++ b/shell/ash.c
-@@ -12888,6 +12888,11 @@ exitshell(void)
-       char *p;
-       int status;
-+#if ENABLE_FEATURE_EDITING_DELAYEDHISTORY
-+      if ((line_input_state->flags & SAVE_HISTORY) && line_input_state->hist_file)
-+              save_history(line_input_state);
-+#endif
-+
-       status = exitstatus;
-       TRACE(("pid %d, exitshell(%d)\n", getpid(), status));
-       if (setjmp(loc.loc)) {
-diff --git a/shell/hush.c b/shell/hush.c
-index e4138ad..a7428d6 100644
---- a/shell/hush.c
-+++ b/shell/hush.c
-@@ -1541,6 +1541,11 @@ static sighandler_t pick_sighandler(unsigned sig)
- static void hush_exit(int exitcode) NORETURN;
- static void hush_exit(int exitcode)
- {
-+#if ENABLE_FEATURE_EDITING_DELAYEDHISTORY
-+      if ((G.line_input_state->flags & SAVE_HISTORY) && G.line_input_state->hist_file)
-+              save_history(G.line_input_state);
-+#endif
-+
-       fflush_all();
-       if (G.exiting <= 0 && G.traps && G.traps[0] && G.traps[0][0]) {
-               char *argv[3];
--- 
-1.7.6
-
diff --git a/debian/patches/0001-lineedit-fix-history-saving-when-history-MAX_HISTORY.patch b/debian/patches/0001-lineedit-fix-history-saving-when-history-MAX_HISTORY.patch
new file mode 100644 (file)
index 0000000..70020fd
--- /dev/null
@@ -0,0 +1,36 @@
+From 75e6cc9e70e426f7cdfd552585506360d7537f7c Mon Sep 17 00:00:00 2001
+From: Dennis Groenen <tj.groenen@gmail.com>
+Date: Wed, 7 Sep 2011 20:24:21 +0200
+Subject: [PATCH 1/4] lineedit: fix history saving when history < MAX_HISTORY
+
+---
+ libbb/lineedit.c |    6 ++----
+ 1 files changed, 2 insertions(+), 4 deletions(-)
+
+diff --git a/libbb/lineedit.c b/libbb/lineedit.c
+index 603bbfc..a8b4609 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.6.1
+
diff --git a/debian/patches/0002-hush-don-t-save-history-when-non-interactive.patch b/debian/patches/0002-hush-don-t-save-history-when-non-interactive.patch
deleted file mode 100644 (file)
index fdf369f..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
---- busybox-1.19.2.orig/shell/hush.c
-+++ busybox-1.19.2/shell/hush.c
-@@ -7831,6 +7831,7 @@ int hush_main(int argc, char **argv)
-                       G.line_input_state->hist_file = hp;
-                       //set_local_var(xasprintf("HISTFILE=%s", ...));
-               }
-+              G.line_input_state->flags &= ~SAVE_HISTORY; /* hush is non-interactive at this point */
- #  if ENABLE_FEATURE_SH_HISTFILESIZE
-               hp = get_local_var_value("HISTFILESIZE");
-               G.line_input_state->max_history = size_from_HISTFILESIZE(hp);
-@@ -8052,6 +8053,12 @@ int hush_main(int argc, char **argv)
-        *    standard output is a terminal
-        * Refer to Posix.2, the description of the 'sh' utility.
-        */
-+#if ENABLE_FEATURE_EDITING
-+# if defined MAX_HISTORY && MAX_HISTORY > 0 && ENABLE_HUSH_SAVEHISTORY
-+      G.line_input_state->flags |= SAVE_HISTORY;
-+# endif
-+#endif
-+
- #if ENABLE_HUSH_JOB
-       if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) {
-               G_saved_tty_pgrp = tcgetpgrp(STDIN_FILENO);
diff --git a/debian/patches/git-backports/0001-lineedit-fix-atomic-replace-of-history-file-hush-fix.patch b/debian/patches/git-backports/0001-lineedit-fix-atomic-replace-of-history-file-hush-fix.patch
new file mode 100644 (file)
index 0000000..5fb4eca
--- /dev/null
@@ -0,0 +1,94 @@
+The following commit has been modified to fit BusyBox 1.19.2 instead of BusyBox git
+--Dennis Groenen <tj.groenen@gmail.com> - 2011-09-10
+
+From 4840ae8a06298e987374fa3cc6d7e4969fd19344 Mon Sep 17 00:00:00 2001
+From: Denys Vlasenko <vda.linux@googlemail.com>
+Date: Sun, 4 Sep 2011 15:28:03 +0200
+Subject: [PATCH 1/3] lineedit: fix atomic replace of history file; hush: fix
+ $HISTFILE handling
+
+Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
+---
+
+--- a/libbb/lineedit.c
++++ b/libbb/lineedit.c
+@@ -1475,7 +1475,7 @@ static void remember_in_history(char *st
+       /* i <= state->max_history */
+       state->cur_history = i;
+       state->cnt_history = i;
+-# if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
++# if ENABLE_FEATURE_EDITING_SAVEHISTORY
+       if ((state->flags & SAVE_HISTORY) && state->hist_file)
+               save_history(str);
+ # endif
+--- a/shell/ash.c
++++ b/shell/ash.c
+@@ -13194,7 +13194,7 @@ int ash_main(int argc UNUSED_PARAM, char
+       }
+       if (sflag || minusc == NULL) {
+-#if defined MAX_HISTORY && MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
++#if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
+               if (iflag) {
+                       const char *hp = lookupvar("HISTFILE");
+                       if (hp)
+--- a/shell/hush.c
++++ b/shell/hush.c
+@@ -7816,27 +7816,7 @@ int hush_main(int argc, char **argv)
+        */
+ #if ENABLE_FEATURE_EDITING
+-      G.line_input_state = new_line_input_t(FOR_SHELL);
+-# if MAX_HISTORY > 0 && ENABLE_HUSH_SAVEHISTORY
+-      {
+-              const char *hp = get_local_var_value("HISTFILE");
+-              if (!hp) {
+-                      hp = get_local_var_value("HOME");
+-                      if (hp)
+-                              hp = concat_path_file(hp, ".hush_history");
+-              } else {
+-                      hp = xstrdup(hp);
+-              }
+-              if (hp) {
+-                      G.line_input_state->hist_file = hp;
+-                      //set_local_var(xasprintf("HISTFILE=%s", ...));
+-              }
+-#  if ENABLE_FEATURE_SH_HISTFILESIZE
+-              hp = get_local_var_value("HISTFILESIZE");
+-              G.line_input_state->max_history = size_from_HISTFILESIZE(hp);
+-#  endif
+-      }
+-# endif
++      G.line_input_state = new_line_input_t(FOR_SHELL & ~SAVE_HISTORY);
+ #endif
+       /* Initialize some more globals to non-zero values */
+@@ -8108,6 +8088,28 @@ int hush_main(int argc, char **argv)
+               /* -1 is special - makes xfuncs longjmp, not exit
+                * (we reset die_sleep = 0 whereever we [v]fork) */
+               enable_restore_tty_pgrp_on_exit(); /* sets die_sleep = -1 */
++
++# if ENABLE_HUSH_SAVEHISTORY && MAX_HISTORY > 0
++              {
++                      const char *hp = get_local_var_value("HISTFILE");
++                      if (!hp) {
++                              hp = get_local_var_value("HOME");
++                              if (hp)
++                                      hp = concat_path_file(hp, ".hush_history");
++                      } else {
++                              hp = xstrdup(hp);
++                      }
++                      if (hp) {
++                              G.line_input_state->hist_file = hp;
++                              G.line_input_state->flags |= SAVE_HISTORY;
++                              //set_local_var(xasprintf("HISTFILE=%s", ...));
++                      }
++#  if ENABLE_FEATURE_SH_HISTFILESIZE
++                      hp = get_local_var_value("HISTFILESIZE");
++                      G.line_input_state->max_history = size_from_HISTFILESIZE(hp);
++#  endif
++              }
++# endif
+       } else {
+               install_special_sighandlers();
+       }
diff --git a/debian/patches/git-backports/0002-lineedit-add-support-for-history-saving-on-exit.patch b/debian/patches/git-backports/0002-lineedit-add-support-for-history-saving-on-exit.patch
new file mode 100644 (file)
index 0000000..3cc7801
--- /dev/null
@@ -0,0 +1,215 @@
+From bede215cf105377a1127532d2d710924cb58cc39 Mon Sep 17 00:00:00 2001
+From: Denys Vlasenko <vda.linux@googlemail.com>
+Date: Sun, 4 Sep 2011 16:12:33 +0200
+Subject: [PATCH 2/3] lineedit: add support for history saving on exit
+
+Based on the patch by Dennis Groenen <tj.groenen@gmail.com>
+
+Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
+---
+ include/libbb.h  |    9 +++++++
+ libbb/Config.src |    7 +++++
+ libbb/lineedit.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++----
+ shell/ash.c      |    4 +++
+ shell/hush.c     |    4 +++
+ 5 files changed, 86 insertions(+), 6 deletions(-)
+
+diff --git a/include/libbb.h b/include/libbb.h
+index 63d0419..91343a9 100644
+--- a/include/libbb.h
++++ b/include/libbb.h
+@@ -1421,6 +1421,12 @@ typedef struct line_input_t {
+       int cur_history;
+       int max_history; /* must never be <= 0 */
+ #  if ENABLE_FEATURE_EDITING_SAVEHISTORY
++      /* meaning of this field depends on FEATURE_EDITING_SAVE_ON_EXIT:
++       * if !FEATURE_EDITING_SAVE_ON_EXIT: "how many lines are
++       * in on-disk history"
++       * if FEATURE_EDITING_SAVE_ON_EXIT: "how many in-memory lines are
++       * also in on-disk history (and thus need to be skipped on save)"
++       */
+       unsigned cnt_history_in_file;
+       const char *hist_file;
+ #  endif
+@@ -1446,6 +1452,9 @@ line_input_t *new_line_input_t(int flags) FAST_FUNC;
+  * >0 length of input string, including terminating '\n'
+  */
+ int read_line_input(line_input_t *st, const char *prompt, char *command, int maxsize, int timeout) FAST_FUNC;
++# if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
++void save_history(line_input_t *st);
++# endif
+ #else
+ #define MAX_HISTORY 0
+ int read_line_input(const char* prompt, char* command, int maxsize) FAST_FUNC;
+diff --git a/libbb/Config.src b/libbb/Config.src
+index aa44236..f6f88b9 100644
+--- a/libbb/Config.src
++++ b/libbb/Config.src
+@@ -94,6 +94,13 @@ config FEATURE_EDITING_SAVEHISTORY
+       help
+         Enable history saving in shells.
++config FEATURE_EDITING_SAVE_ON_EXIT
++      bool "Save history on shell exit, not after every command"
++      default n
++      depends on FEATURE_EDITING_SAVEHISTORY
++      help
++        Save history on shell exit, not after every command.
++
+ config FEATURE_REVERSE_SEARCH
+       bool "Reverse history search"
+       default y
+diff --git a/libbb/lineedit.c b/libbb/lineedit.c
+index 5d13904..0786f9a 100644
+--- a/libbb/lineedit.c
++++ b/libbb/lineedit.c
+@@ -1351,7 +1351,9 @@ 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));
+-              st_parm->cnt_history_in_file = idx = 0;
++              idx = 0;
++              if (!ENABLE_FEATURE_EDITING_SAVE_ON_EXIT)
++                      st_parm->cnt_history_in_file = 0;
+               while ((line = xmalloc_fgetline(fp)) != NULL) {
+                       if (line[0] == '\0') {
+                               free(line);
+@@ -1359,7 +1361,8 @@ static void load_history(line_input_t *st_parm)
+                       }
+                       free(temp_h[idx]);
+                       temp_h[idx] = line;
+-                      st_parm->cnt_history_in_file++;
++                      if (!ENABLE_FEATURE_EDITING_SAVE_ON_EXIT)
++                              st_parm->cnt_history_in_file++;
+                       idx++;
+                       if (idx == st_parm->max_history)
+                               idx = 0;
+@@ -1389,15 +1392,66 @@ static void load_history(line_input_t *st_parm)
+                       st_parm->history[i++] = line;
+               }
+               st_parm->cnt_history = i;
++              if (ENABLE_FEATURE_EDITING_SAVE_ON_EXIT)
++                      st_parm->cnt_history_in_file = i;
+       }
+ }
+-/* state->flags is already checked to be nonzero */
++#  if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
++void save_history(line_input_t *st)
++{
++      FILE *fp;
++
++      if (!(st->flags & SAVE_HISTORY))
++              return;
++      if (!st->hist_file)
++              return;
++      if (st->cnt_history <= st->cnt_history_in_file)
++              return;
++
++      fp = fopen(st->hist_file, "a");
++      if (fp) {
++              int i, fd;
++              char *new_name;
++              line_input_t *st_temp;
++
++              for (i = st->cnt_history_in_file; i < st->cnt_history; i++)
++                      fprintf(fp, "%s\n", st->history[i]);
++              fclose(fp);
++
++              /* we may have concurrently written entries from others.
++               * load them */
++              st_temp = new_line_input_t(st->flags);
++              st_temp->hist_file = st->hist_file;
++              st_temp->max_history = st->max_history;
++              load_history(st_temp);
++
++              /* write out temp file and replace hist_file atomically */
++              new_name = xasprintf("%s.%u.new", st->hist_file, (int) getpid());
++              fd = open(new_name, O_WRONLY | O_CREAT | O_TRUNC, 0600);
++              if (fd >= 0) {
++                      fp = xfdopen_for_write(fd);
++                      for (i = 0; i < st_temp->cnt_history; i++)
++                              fprintf(fp, "%s\n", st_temp->history[i]);
++                      fclose(fp);
++                      if (rename(new_name, st->hist_file) == 0)
++                              st->cnt_history_in_file = st_temp->cnt_history;
++              }
++              free(new_name);
++              free_line_input_t(st_temp);
++      }
++}
++#  else
+ static void save_history(char *str)
+ {
+       int fd;
+       int len, len2;
++      if (!(state->flags & SAVE_HISTORY))
++              return;
++      if (!state->hist_file)
++              return;
++
+       fd = open(state->hist_file, O_WRONLY | O_CREAT | O_APPEND, 0600);
+       if (fd < 0)
+               return;
+@@ -1441,6 +1495,7 @@ static void save_history(char *str)
+               free_line_input_t(st_temp);
+       }
+ }
++#  endif
+ # else
+ #  define load_history(a) ((void)0)
+ #  define save_history(a) ((void)0)
+@@ -1469,15 +1524,16 @@ static void remember_in_history(char *str)
+               for (i = 0; i < state->max_history-1; i++)
+                       state->history[i] = state->history[i+1];
+               /* i == state->max_history-1 */
++              if (ENABLE_FEATURE_EDITING_SAVE_ON_EXIT && state->cnt_history_in_file)
++                      state->cnt_history_in_file--;
+       }
+       /* i <= state->max_history-1 */
+       state->history[i++] = xstrdup(str);
+       /* i <= state->max_history */
+       state->cur_history = i;
+       state->cnt_history = i;
+-# if ENABLE_FEATURE_EDITING_SAVEHISTORY
+-      if ((state->flags & SAVE_HISTORY) && state->hist_file)
+-              save_history(str);
++# if ENABLE_FEATURE_EDITING_SAVEHISTORY && !ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
++      save_history(str);
+ # endif
+       IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;)
+ }
+diff --git a/shell/ash.c b/shell/ash.c
+index bf376bd..14472cb 100644
+--- a/shell/ash.c
++++ b/shell/ash.c
+@@ -12888,6 +12888,10 @@ exitshell(void)
+       char *p;
+       int status;
++#if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
++      save_history(line_input_state);
++#endif
++
+       status = exitstatus;
+       TRACE(("pid %d, exitshell(%d)\n", getpid(), status));
+       if (setjmp(loc.loc)) {
+diff --git a/shell/hush.c b/shell/hush.c
+index 42143fd..a9e2dd3 100644
+--- a/shell/hush.c
++++ b/shell/hush.c
+@@ -1541,6 +1541,10 @@ static sighandler_t pick_sighandler(unsigned sig)
+ static void hush_exit(int exitcode) NORETURN;
+ static void hush_exit(int exitcode)
+ {
++#if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT
++      save_history(G.line_input_state);
++#endif
++
+       fflush_all();
+       if (G.exiting <= 0 && G.traps && G.traps[0] && G.traps[0][0]) {
+               char *argv[3];
+-- 
+1.7.6.1
+
diff --git a/debian/patches/git-backports/0003-lineedit-remove-SAVE_HISTORY-bit-hist_file-can-be-us.patch b/debian/patches/git-backports/0003-lineedit-remove-SAVE_HISTORY-bit-hist_file-can-be-us.patch
new file mode 100644 (file)
index 0000000..9b6b624
--- /dev/null
@@ -0,0 +1,92 @@
+From e45af7ad17c3f0ecaec1d761aa89cb4fd83afbc2 Mon Sep 17 00:00:00 2001
+From: Denys Vlasenko <vda.linux@googlemail.com>
+Date: Sun, 4 Sep 2011 16:15:24 +0200
+Subject: [PATCH 3/3] lineedit: remove SAVE_HISTORY bit, ->hist_file can be
+ used as indicator
+
+Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
+---
+ include/libbb.h  |   13 ++++++-------
+ libbb/lineedit.c |    6 +-----
+ shell/hush.c     |    3 +--
+ 3 files changed, 8 insertions(+), 14 deletions(-)
+
+diff --git a/include/libbb.h b/include/libbb.h
+index 91343a9..1ca4489 100644
+--- a/include/libbb.h
++++ b/include/libbb.h
+@@ -1434,13 +1434,12 @@ typedef struct line_input_t {
+ # endif
+ } line_input_t;
+ enum {
+-      DO_HISTORY = 1 * (MAX_HISTORY > 0),
+-      SAVE_HISTORY = 2 * (MAX_HISTORY > 0) * ENABLE_FEATURE_EDITING_SAVEHISTORY,
+-      TAB_COMPLETION = 4 * ENABLE_FEATURE_TAB_COMPLETION,
+-      USERNAME_COMPLETION = 8 * ENABLE_FEATURE_USERNAME_COMPLETION,
+-      VI_MODE = 0x10 * ENABLE_FEATURE_EDITING_VI,
+-      WITH_PATH_LOOKUP = 0x20,
+-      FOR_SHELL = DO_HISTORY | SAVE_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION,
++      DO_HISTORY       = 1 * (MAX_HISTORY > 0),
++      TAB_COMPLETION   = 2 * ENABLE_FEATURE_TAB_COMPLETION,
++      USERNAME_COMPLETION = 4 * ENABLE_FEATURE_USERNAME_COMPLETION,
++      VI_MODE          = 8 * ENABLE_FEATURE_EDITING_VI,
++      WITH_PATH_LOOKUP = 0x10,
++      FOR_SHELL        = DO_HISTORY | TAB_COMPLETION | USERNAME_COMPLETION,
+ };
+ line_input_t *new_line_input_t(int flags) FAST_FUNC;
+ /* So far static: void free_line_input_t(line_input_t *n) FAST_FUNC; */
+diff --git a/libbb/lineedit.c b/libbb/lineedit.c
+index 0786f9a..603bbfc 100644
+--- a/libbb/lineedit.c
++++ b/libbb/lineedit.c
+@@ -1402,8 +1402,6 @@ void save_history(line_input_t *st)
+ {
+       FILE *fp;
+-      if (!(st->flags & SAVE_HISTORY))
+-              return;
+       if (!st->hist_file)
+               return;
+       if (st->cnt_history <= st->cnt_history_in_file)
+@@ -1447,8 +1445,6 @@ static void save_history(char *str)
+       int fd;
+       int len, len2;
+-      if (!(state->flags & SAVE_HISTORY))
+-              return;
+       if (!state->hist_file)
+               return;
+@@ -2188,7 +2184,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
+       state = st ? st : (line_input_t*) &const_int_0;
+ #if MAX_HISTORY > 0
+ # if ENABLE_FEATURE_EDITING_SAVEHISTORY
+-      if ((state->flags & SAVE_HISTORY) && state->hist_file)
++      if (state->hist_file)
+               if (state->cnt_history == 0)
+                       load_history(state);
+ # endif
+diff --git a/shell/hush.c b/shell/hush.c
+index a9e2dd3..7a34f59 100644
+--- a/shell/hush.c
++++ b/shell/hush.c
+@@ -7820,7 +7820,7 @@ int hush_main(int argc, char **argv)
+        */
+ #if ENABLE_FEATURE_EDITING
+-      G.line_input_state = new_line_input_t(FOR_SHELL & ~SAVE_HISTORY);
++      G.line_input_state = new_line_input_t(FOR_SHELL);
+ #endif
+       /* Initialize some more globals to non-zero values */
+@@ -8105,7 +8105,6 @@ int hush_main(int argc, char **argv)
+                       }
+                       if (hp) {
+                               G.line_input_state->hist_file = hp;
+-                              G.line_input_state->flags |= SAVE_HISTORY;
+                               //set_local_var(xasprintf("HISTFILE=%s", ...));
+                       }
+ #  if ENABLE_FEATURE_SH_HISTFILESIZE
+-- 
+1.7.6.1
+
index 5ee93e5..ec3109d 100644 (file)
@@ -19,9 +19,13 @@ parse-complete-hostname.patch
 #New patches as per reported issues by users
 showkey-default-option.patch
 ps-accept-and-ignore-missing-options.patch
-0001-add-support-for-delayed-history-saving.patch
-0002-hush-don-t-save-history-when-non-interactive.patch
 
 #Hotfixes
 hotfixes/busybox-1.19.2-crond.patch
 
+#Patched pulled from busybox git
+git-backports/0001-lineedit-fix-atomic-replace-of-history-file-hush-fix.patch
+git-backports/0002-lineedit-add-support-for-history-saving-on-exit.patch
+git-backports/0003-lineedit-remove-SAVE_HISTORY-bit-hist_file-can-be-us.patch
+
+0001-lineedit-fix-history-saving-when-history-MAX_HISTORY.patch