Skip to content

Commit 0afe9dc

Browse files
hotpxlPeter Stephenson
authored andcommitted
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.
1 parent e25de2d commit 0afe9dc

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2019-02-18 Peter Stephenson <p.stephenson@samsung.com>
2+
3+
* Yutian Li: 44067: Src/hist.c: If history read was interrupted,
4+
don't assume next time it was correctly read.
5+
16
2019-02-14 Peter Stephenson <p.stephenson@samsung.com>
27

38
* see 44062: back off change to ZLE per-line initiialisation,

Src/hist.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ static struct histfile_stats {
216216
char *text;
217217
time_t stim, mtim;
218218
off_t fpos, fsiz;
219+
int interrupted;
219220
zlong next_write_ev;
220221
} lasthist;
221222

@@ -2544,11 +2545,13 @@ readhistfile(char *fn, int err, int readflags)
25442545
sb.st_size == 0)
25452546
return;
25462547
if (readflags & HFILE_FAST) {
2547-
if ((lasthist.fsiz == sb.st_size && lasthist.mtim == sb.st_mtime)
2548-
|| lockhistfile(fn, 0))
2548+
if (!lasthist.interrupted &&
2549+
((lasthist.fsiz == sb.st_size && lasthist.mtim == sb.st_mtime)
2550+
|| lockhistfile(fn, 0)))
25492551
return;
25502552
lasthist.fsiz = sb.st_size;
25512553
lasthist.mtim = sb.st_mtime;
2554+
lasthist.interrupted = 0;
25522555
} else if ((ret = lockhistfile(fn, 1))) {
25532556
if (ret == 2) {
25542557
zwarn("locking failed for %s: %e: reading anyway", fn, errno);
@@ -2694,8 +2697,11 @@ readhistfile(char *fn, int err, int readflags)
26942697
*/
26952698
if (uselex || remeta)
26962699
freeheap();
2697-
if (errflag & ERRFLAG_INT)
2700+
if (errflag & ERRFLAG_INT) {
2701+
/* Can't assume fast read next time if interrupted. */
2702+
lasthist.interrupted = 1;
26982703
break;
2704+
}
26992705
}
27002706
if (start && readflags & HFILE_USE_OPTIONS) {
27012707
zsfree(lasthist.text);

0 commit comments

Comments
 (0)