Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: No fsync on history file? I lost my history



On 2018-09-23 15:45:17 +0000, Daniel Shahaf wrote:
> > > > +++ b/Src/hist.c
> > > > @@ -2933,6 +2933,9 @@ savehistfile(char *fn, int err, int writeflags)
> > > >  		lasthist.text = ztrdup(start);
> > > >  	    }
> > > >  	}
> > > > +	fflush(out); /* need to flush before fsync */
> > > 
> > > Isn't the fflush() on line 2927 sufficient?  (Even if it isn't, I would have
> > > expected a ret>=0 guard around this call.)
> > 
> > It should call write(2) to write out the buffered data. Then the kernel
> > can fsync the data to disk. A guard has been added.
> 
> Yes, I understand that fflush(3) must be called in order to flush data
> from libc's buffers into kernel buffers, which fsync(2) will later flush
> to disk.  My question was whether the fflush() call being added was
> redundant because of the existing call on line 2927.  It would be odd
> to have two fflush() calls in a row without fwrite() between them; and
> to have only one of them update lasthist.

But the first one is in a "if", thus might have not been called. Or
there is an inconsistency in the conditions, which should be fixed.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



Messages sorted by: Reverse Date, Date, Thread, Author