add and enable new ash history buffer patch
authorDennis Groenen <tj.groenen@gmail.com>
Thu, 21 Jul 2011 15:06:16 +0000 (17:06 +0200)
committerDennis Groenen <tj.groenen@gmail.com>
Thu, 21 Jul 2011 15:06:16 +0000 (17:06 +0200)
debian/config/config.maemo
debian/patches/ash-history-buffer.patch [new file with mode: 0644]
debian/patches/series

index b31c6a3..ad76983 100644 (file)
@@ -944,6 +944,8 @@ CONFIG_ASH_CMDCMD=y
 CONFIG_ASH_OPTIMIZE_FOR_SIZE=y
 CONFIG_ASH_RANDOM_SUPPORT=y
 CONFIG_ASH_EXPAND_PRMT=y
+CONFIG_ASH_HIST_BUFFER=y
+CONFIG_ASH_HIST_BUFFER_PATH="/tmp"
 CONFIG_CTTYHACK=y
 CONFIG_HUSH=y
 CONFIG_HUSH_BASH_COMPAT=y
diff --git a/debian/patches/ash-history-buffer.patch b/debian/patches/ash-history-buffer.patch
new file mode 100644 (file)
index 0000000..dc4074d
--- /dev/null
@@ -0,0 +1,90 @@
+--- a/shell/ash.c
++++ b/shell/ash.c
+@@ -182,6 +182,24 @@
+ //config:       This option recreates the prompt string from the environment
+ //config:       variable each time it is displayed.
+ //config:
++//config:config ASH_HIST_BUFFER
++//config:     bool "History buffer"
++//config:     default n
++//config:     depends on ASH && FEATURE_EDITING_SAVEHISTORY
++//config:     help
++//config:       Allows you to set a temporary location for .ash_history.
++//config:       History is saved to this custom location, and written out to
++//config:       its default location (~/.ash_history) upon shell exit.
++//config:       Useful to prevent wear on flash-based storage devices.
++//config:
++//config:config ASH_HIST_BUFFER_PATH
++//config:     string "History buffer location"
++//config:     default "/tmp"
++//config:     depends on ASH && ASH_HIST_BUFFER
++//config:     help
++//config:       Directory which will be used to save the shell history until
++//config:       ash is exited.
++//config:
+ //usage:#define ash_trivial_usage NOUSAGE_STR
+ //usage:#define ash_full_usage ""
+@@ -12810,6 +12828,14 @@ exitshell(void)
+       char *p;
+       int status;
++#if ENABLE_ASH_HIST_BUFFER
++      const char *tmphistory = lookupvar("HISTFILE");
++      const char *storedhistory = lookupvar("STOREDHISTFILE");
++
++      if (storedhistory != NULL) /* is NULL when setting up the history buffer failed; check this before copying */
++              copy_file(tmphistory, storedhistory, FILEUTILS_FORCE | FILEUTILS_DEREFERENCE | FILEUTILS_PRESERVE_STATUS);
++#endif
++
+       status = exitstatus;
+       TRACE(("pid %d, exitshell(%d)\n", getpid(), status));
+       if (setjmp(loc.loc)) {
+@@ -13056,9 +13082,47 @@ int ash_main(int argc UNUSED_PARAM, char
+               if (hp == NULL) {
+                       hp = lookupvar("HOME");
+                       if (hp != NULL) {
++#if ENABLE_ASH_HIST_BUFFER
++                              char *tmppath;
++                              char *tmphistory;
++                              char *storedhistory;
++                              const char *user = lookupvar("USER");
++
++                              tmppath = concat_path_file(CONFIG_ASH_HIST_BUFFER_PATH, user);
++                              storedhistory = concat_path_file(hp, ".ash_history");
++
++                              if (access(CONFIG_ASH_HIST_BUFFER_PATH, R_OK == -1)) {
++                                      bb_simple_perror_msg("could not access history buffer path");
++                                      goto bail;
++                              }
++                              if (bb_make_directory(tmppath, 0700, FILEUTILS_RECUR)) {
++                                      /* bb_make_directory is noisy, no need for an additional error message here */
++                                      goto bail;
++                              }
++
++                              tmphistory = concat_path_file(tmppath, ".ash_history");
++                              if (access(storedhistory, R_OK) == -1)
++                                      creat(tmphistory, 0664);
++                              if (access(tmphistory, R_OK | W_OK) == -1) /* copy stored history to buffer locaton if the latter is non-existant */
++                                      copy_file(storedhistory, tmphistory, FILEUTILS_FORCE | FILEUTILS_DEREFERENCE | FILEUTILS_PRESERVE_STATUS);
++
++                              setvar("STOREDHISTFILE", storedhistory, 0);
++                              goto out;
++
++ bail:
++                              errno = 0;
++                              bb_simple_perror_msg("shell history will not be saved");
++                              tmphistory = xasprintf("/dev/null");
++ out:
++                              setvar("HISTFILE", tmphistory, 0);
++                              free(storedhistory);
++                              free(tmphistory);
++                              free(tmppath);
++#else
+                               char *defhp = concat_path_file(hp, ".ash_history");
+                               setvar("HISTFILE", defhp, 0);
+                               free(defhp);
++#endif
+                       }
+               }
+       }
index b267641..e566078 100644 (file)
@@ -6,6 +6,7 @@ init-console.patch
 version.patch
 
 #Patches ported from Nokia's busybox sources
+ash-history-buffer.patch
 03tar.patch
 05thumb.patch
 06ls.patch