summaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
authorGlenn L McGrath2002-12-09 11:10:40 +0000
committerGlenn L McGrath2002-12-09 11:10:40 +0000
commitfdbbb048933389c5a2624aa77aa5af2dbea75b01 (patch)
tree41623dd3faac0290e7739fde7c7228f7fa47e18e /shell/ash.c
parent6b5bd0e5abbfb6b3b925dfd8452c72589569981b (diff)
downloadbusybox-fdbbb048933389c5a2624aa77aa5af2dbea75b01.zip
busybox-fdbbb048933389c5a2624aa77aa5af2dbea75b01.tar.gz
Command line history changes, lastpatch_71 from Vladimir N. Oleynik
Diffstat (limited to 'shell/ash.c')
-rw-r--r--shell/ash.c48
1 files changed, 40 insertions, 8 deletions
diff --git a/shell/ash.c b/shell/ash.c
index bec37cf..7151690 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -1196,6 +1196,10 @@ static struct var vlc_all;
static struct var vlc_ctype;
#endif
+#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY
+static struct var vhistfile;
+#endif
+
struct varinit {
struct var *var;
int flags;
@@ -1242,6 +1246,10 @@ static const struct varinit varinit[] = {
{&vlc_ctype, VSTRFIXED | VTEXTFIXED | VUNSET, "LC_CTYPE=",
change_lc_ctype},
#endif
+#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY
+ {&vhistfile, VSTRFIXED | VTEXTFIXED | VUNSET, "HISTFILE=",
+ NULL},
+#endif
{NULL, 0, NULL,
NULL}
};
@@ -7312,6 +7320,20 @@ int ash_main(int argc, char **argv)
init();
setstackmark(&smark);
procargs(argc, argv);
+#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY
+ if ( iflag ) {
+ const char *hp = lookupvar("HISTFILE");
+
+ if(hp == NULL ) {
+ hp = lookupvar("HOME");
+ if(hp != NULL) {
+ char *defhp = concat_path_file(hp, ".ash_history");
+ setvar("HISTFILE", defhp, 0);
+ free(defhp);
+ }
+ }
+ }
+#endif
if (argv[0] && argv[0][0] == '-')
isloginsh = 1;
if (isloginsh) {
@@ -7357,8 +7379,12 @@ int ash_main(int argc, char **argv)
if (sflag || minusc == NULL) {
state4: /* XXX ??? - why isn't this before the "if" statement */
#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY
- if ( iflag )
- load_history ( ".ash_history" );
+ if ( iflag ) {
+ const char *hp = lookupvar("HISTFILE");
+
+ if(hp != NULL )
+ load_history ( hp );
+ }
#endif
cmdloop(1);
}
@@ -7550,10 +7576,6 @@ static int exitcmd(int argc, char **argv)
{
if (stoppedjobs())
return 0;
-#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY
- if ( iflag )
- save_history ( ".ash_history" );
-#endif
if (argc > 1)
exitstatus = number(argv[1]);
@@ -11615,12 +11637,22 @@ static void exitshell(int status)
trap[0] = NULL;
evalstring(p, 0);
}
- l1:handler = &loc2; /* probably unnecessary */
+l1:
+ handler = &loc2; /* probably unnecessary */
flushall();
#ifdef CONFIG_ASH_JOB_CONTROL
setjobctl(0);
#endif
- l2:_exit(status);
+#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY
+ if (iflag && rootshell) {
+ const char *hp = lookupvar("HISTFILE");
+
+ if(hp != NULL )
+ save_history ( hp );
+ }
+#endif
+l2:
+ _exit(status);
/* NOTREACHED */
}