Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: No fsync on history file? I lost my history
- X-seq: zsh-users 23672
- From: lilydjwg <lilydjwg@xxxxxxxxx>
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- Subject: Re: No fsync on history file? I lost my history
- Date: Sun, 23 Sep 2018 22:22:55 +0800
- Cc: zsh-users@xxxxxxx
- Disposition-notification-to: lilydjwg@xxxxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:disposition-notification-to :user-agent; bh=ZqYydotw+v62l2UUsb2Hb8w9VM9WPzpt2+pGRNqdtK8=; b=CEC9ATjRAg/MfgOe2QhL0NTSvy8bMhll4foVGwnxaQt02p9olPvM7b+w1IBABABcK8 5/d0ZONr/ejjXKKWiseNZ9Um+C32z4Dc+aYJQIDpeHaI4lJ3GjFUTiehmVbPvB68tQwx N+0BAKJY+A84DDyBpgD1sh4jFxg020BuNohcbqHfZtDAPQLuKrxTldZA+yhz0OVlq856 CUI8apHB8IBhznzRfEkZDlJmS92LgAjDvLJJOUFkXk1hHBnP1kvlhHTsEx7Vr19KzgAb CK7VfagK92w2sbq6K4xGIlCe8XQDTaU1KLfeKJ+o2GXwSp7Qj4IapA+P6vOyWFU2VRDG OJfw==
- In-reply-to: <1537709747.103981.1517680056.72C7A43E@webmail.messagingengine.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20180923085246.GA19251@lilyforest.localdomain> <1537709747.103981.1517680056.72C7A43E@webmail.messagingengine.com>
On Sun, Sep 23, 2018 at 01:35:47PM +0000, Daniel Shahaf wrote:
> lilydjwg wrote on Sun, 23 Sep 2018 16:52 +0800:
> > Would you add the fsync call or make an option for that?
>
> I'd be happy to accept patches for this.
Here it is. I've checked that it works on my Linux system, but not sure
about other systems.
--
Best regards,
lilydjwg
From 78b1df1329b2c7bb2b6e78e5b7d70be4bbf103e2 Mon Sep 17 00:00:00 2001
From: lilydjwg <lilydjwg@xxxxxxxxx>
Date: Sun, 23 Sep 2018 22:12:56 +0800
Subject: [PATCH] Call fsync after writing out new histfile
to ensure the data is on disk before the rename in case of a system crash.
---
Src/hist.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Src/hist.c b/Src/hist.c
index dbdc1e4e5..e128e9f14 100644
--- a/Src/hist.c
+++ 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 */
+ if (fsync(fileno(out)) < 0 && ret >= 0)
+ ret = -1;
if (fclose(out) < 0 && ret >= 0)
ret = -1;
if (ret >= 0) {
--
2.19.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author