Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
skip rewriting history if exiting due to signal
- X-seq: zsh-workers 20438
- From: Wayne Davison <wayned@xxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: skip rewriting history if exiting due to signal
- Date: Fri, 1 Oct 2004 12:36:58 -0700
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
Here's my patch that implements the behavior that skips the history
rewrite-after-appending if zsh is exiting because it received a signal.
This should make the simultaneous closing of multiple zsh programs less
contentious over the history file. The safest way to go is to use
INC_APPEND_HISTORY or SHARE_HISTORY (since new history lines are being
appended as they are entered, not all at once on exit).
People who don't append to the history file won't see any change in
behavior from this patch (that will have to be improved in some other
manner, possibly by switching over to using a *.new file to write out
the new history lines).
..wayne..
--- Src/builtin.c 1 Oct 2004 18:51:44 -0000 1.127
+++ Src/builtin.c 1 Oct 2004 19:12:23 -0000
@@ -1340,7 +1340,7 @@ bin_fc(char *nam, char **argv, Options o
zwarnnam("fc", "too many arguments", NULL, 0);
return 1;
}
- return !saveandpophiststack(-1);
+ return !saveandpophiststack(-1, HFILE_USE_OPTIONS);
}
/* with the -m option, the first argument is taken *
* as a pattern that history lines have to match */
@@ -4111,8 +4111,11 @@ zexit(int val, int from_where)
}
if (isset(RCS) && interact) {
if (!nohistsave) {
- saveandpophiststack(1);
- savehistfile(NULL, 1, HFILE_USE_OPTIONS);
+ int writeflags = HFILE_USE_OPTIONS;
+ if (from_where == 1)
+ writeflags |= HFILE_NO_REWRITE;
+ saveandpophiststack(1, writeflags);
+ savehistfile(NULL, 1, writeflags);
}
if (islogin && !subsh) {
sourcehome(".zlogout");
--- Src/hist.c 9 Sep 2004 10:12:47 -0000 1.53
+++ Src/hist.c 1 Oct 2004 19:12:24 -0000
@@ -2093,7 +2093,8 @@ savehistfile(char *fn, int err, int writ
}
fclose(out);
- if ((writeflags & (HFILE_SKIPOLD | HFILE_FAST)) == HFILE_SKIPOLD) {
+ if (writeflags & HFILE_SKIPOLD
+ && !(writeflags & (HFILE_FAST | HFILE_NO_REWRITE))) {
int remember_histactive = histactive;
/* Zeroing histactive avoids unnecessary munging of curline. */
@@ -2445,7 +2446,7 @@ pophiststack(void)
/**/
int
-saveandpophiststack(int pop_through)
+saveandpophiststack(int pop_through, int writeflags)
{
if (pop_through <= 0) {
pop_through += histsave_stack_pos + 1;
@@ -2459,7 +2460,7 @@ saveandpophiststack(int pop_through)
return 0;
do {
if (!nohistsave)
- savehistfile(NULL, 1, HFILE_USE_OPTIONS);
+ savehistfile(NULL, 1, writeflags);
pophiststack();
} while (histsave_stack_pos >= pop_through);
return 1;
--- Src/params.c 1 Oct 2004 19:06:49 -0000 1.91
+++ Src/params.c 1 Oct 2004 19:12:24 -0000
@@ -3611,7 +3611,8 @@ mod_export void
endparamscope(void)
{
locallevel--;
- saveandpophiststack(0); /* Pops anything from a higher locallevel */
+ /* This pops anything from a higher locallevel */
+ saveandpophiststack(0, HFILE_USE_OPTIONS);
scanhashtable(paramtab, 0, 0, 0, scanendscope, 0);
}
--- Src/zsh.h 9 Sep 2004 10:12:47 -0000 1.60
+++ Src/zsh.h 1 Oct 2004 19:10:59 -0000 1.62
@@ -1365,6 +1365,7 @@ struct histent {
#define HFILE_SKIPDUPS 0x0004
#define HFILE_SKIPFOREIGN 0x0008
#define HFILE_FAST 0x0010
+#define HFILE_NO_REWRITE 0x0020
#define HFILE_USE_OPTIONS 0x8000
/******************************************/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author