part 2: don’t stop using the history if the file has been truncated

This commit is contained in:
tg 2017-08-07 20:43:00 +00:00
parent bfa79a4e4b
commit c203e7c5b2
1 changed files with 6 additions and 5 deletions

View File

@ -27,7 +27,7 @@
#include <sys/file.h> #include <sys/file.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.163 2017/08/07 20:40:57 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.164 2017/08/07 20:43:00 tg Exp $");
Trap sigtraps[ksh_NSIG + 1]; Trap sigtraps[ksh_NSIG + 1];
static struct sigaction Sigact_ign; static struct sigaction Sigact_ign;
@ -963,10 +963,11 @@ writehistfile(int lno, const char *cmd)
mksh_lockfd(histfd); mksh_lockfd(histfd);
sizenow = lseek(histfd, (off_t)0, SEEK_END); sizenow = lseek(histfd, (off_t)0, SEEK_END);
if (sizenow < histfsize) { if (sizenow < histfsize) {
/* the file has shrunk; give up */ /* the file has shrunk; trust it just appending the new data */
goto bad; /* well, for now, anyway… since mksh strdups all into memory */
} /* we can use a nicer approach some time later… */
if ( ;
} else if (
/* ignore changes when the file is too large */ /* ignore changes when the file is too large */
sizenow <= MKSH_MAXHISTFSIZE sizenow <= MKSH_MAXHISTFSIZE
&& &&