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

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



lilydjwg wrote on Sun, 23 Sep 2018 22:22 +0800:
> Here it is. I've checked that it works on my Linux system, but not sure
> about other systems.

fsync() is in POSIX.  I assume we can just call it, but if somebody complains
we'll need to use an HAVE_FSYNC guard.

> +++ 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.)

> +	if (fsync(fileno(out)) < 0 && ret >= 0)
> +	    ret = -1;

fileno() can return -1.

Shouldn't the ret>=0 check happen before the calls to fileno() and fsync()?

>  	if (fclose(out) < 0 && ret >= 0)
>  	    ret = -1;
>  	if (ret >= 0) {

Cheers,

Daniel



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