summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYutian Li <hotpxless@gmail.com>2019-02-16 23:40:15 -0500
committerPeter Stephenson <p.stephenson@samsung.com>2019-02-18 10:10:00 +0000
commit0afe9dc02a941be1f910b89af7e5f6d342503978 (patch)
tree8d903b222f4850732a1f87ecf73cb9554756bdda
parente25de2de74be09071a8f752d38263cab9c316254 (diff)
downloadzsh-0afe9dc02a941be1f910b89af7e5f6d342503978.tar.gz
zsh-0afe9dc02a941be1f910b89af7e5f6d342503978.zip
44067: Make history read safer on interrupt.
Record if a read was interrupted and if so process it in full next time a read is needed.
-rw-r--r--ChangeLog5
-rw-r--r--Src/hist.c12
2 files changed, 14 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 63dadc319..a1afc5115 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-02-18 Peter Stephenson <p.stephenson@samsung.com>
+
+ * Yutian Li: 44067: Src/hist.c: If history read was interrupted,
+ don't assume next time it was correctly read.
+
2019-02-14 Peter Stephenson <p.stephenson@samsung.com>
* see 44062: back off change to ZLE per-line initiialisation,
diff --git a/Src/hist.c b/Src/hist.c
index dbdc1e4e5..f7e53de74 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -216,6 +216,7 @@ static struct histfile_stats {
char *text;
time_t stim, mtim;
off_t fpos, fsiz;
+ int interrupted;
zlong next_write_ev;
} lasthist;
@@ -2544,11 +2545,13 @@ readhistfile(char *fn, int err, int readflags)
sb.st_size == 0)
return;
if (readflags & HFILE_FAST) {
- if ((lasthist.fsiz == sb.st_size && lasthist.mtim == sb.st_mtime)
- || lockhistfile(fn, 0))
+ if (!lasthist.interrupted &&
+ ((lasthist.fsiz == sb.st_size && lasthist.mtim == sb.st_mtime)
+ || lockhistfile(fn, 0)))
return;
lasthist.fsiz = sb.st_size;
lasthist.mtim = sb.st_mtime;
+ lasthist.interrupted = 0;
} else if ((ret = lockhistfile(fn, 1))) {
if (ret == 2) {
zwarn("locking failed for %s: %e: reading anyway", fn, errno);
@@ -2694,8 +2697,11 @@ readhistfile(char *fn, int err, int readflags)
*/
if (uselex || remeta)
freeheap();
- if (errflag & ERRFLAG_INT)
+ if (errflag & ERRFLAG_INT) {
+ /* Can't assume fast read next time if interrupted. */
+ lasthist.interrupted = 1;
break;
+ }
}
if (start && readflags & HFILE_USE_OPTIONS) {
zsfree(lasthist.text);