about summary refs log tree commit diff
path: root/Src/hist.c
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 /Src/hist.c
parente25de2de74be09071a8f752d38263cab9c316254 (diff)
downloadzsh-0afe9dc02a941be1f910b89af7e5f6d342503978.tar.gz
zsh-0afe9dc02a941be1f910b89af7e5f6d342503978.tar.xz
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.
Diffstat (limited to 'Src/hist.c')
-rw-r--r--Src/hist.c12
1 files changed, 9 insertions, 3 deletions
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);