From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-users-return-23672-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 6d56a070 for ; Sun, 23 Sep 2018 14:23:48 +0000 (UTC) Received: (qmail 13698 invoked by alias); 23 Sep 2018 14:23:36 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23672 Received: (qmail 27995 invoked by uid 1010); 23 Sep 2018 14:23:35 -0000 X-Qmail-Scanner-Diagnostics: from mail-pg1-f193.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.215.193):SA:0(-1.6/5.0):. Processed in 2.194624 secs); 23 Sep 2018 14:23:35 -0000 X-Envelope-From: lilydjwg@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state: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=EYk7rZ29DxUcxmKwzcNOWNbHsTOARmZVA7lTPriVNKHHp2JNujtaetq5JUcHgau5/H b+DcUKMMWmviy2njz9IrasNHj+M7cMGJIS9m5ldmsxVDBvejCjugZfGsJk9TUO7e7hdr QYM69vOkKTwq+UDGMdhwBZUyqzasxPpFtoEKGN0DTijMa24Tw9q8L5JPbYDzLgJrtjuK 4voeukN4D8KQoJQMsn/pZs6qcTrItb5iA0xHiFsmqiNKALmv6UoI827m3AaxJktTvhy8 waynd/iTb7c9jh//GpoyzzOETAyYFYKxj7YkKYZPTfirHXDaUb94lqzIHS/qnMYVJOkA o1Mg== X-Gm-Message-State: APzg51DrqIl6EL+OLyajt323f3vGy2o1yVZAhljGiyGpwjy51znzMtH+ ir/zDHvSxg+UL/zBKRr2NxFMfUpCSWw= X-Google-Smtp-Source: ANB0VdaffMbTjwAkWqCpD67Z4T2qKwEVZd3yqEFeNZwPwhs0PYe1s/A+CE+gS6eOP8Jy6Sr8i9PA2g== X-Received: by 2002:a62:2904:: with SMTP id p4-v6mr6596663pfp.128.1537712610742; Sun, 23 Sep 2018 07:23:30 -0700 (PDT) Date: Sun, 23 Sep 2018 22:22:55 +0800 From: lilydjwg To: Daniel Shahaf Cc: zsh-users@zsh.org Subject: Re: No fsync on history file? I lost my history Message-ID: <20180923142255.GA4931@lilyforest.localdomain> References: <20180923085246.GA19251@lilyforest.localdomain> <1537709747.103981.1517680056.72C7A43E@webmail.messagingengine.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="PEIAKu/WMn1b1Hv9" Content-Disposition: inline In-Reply-To: <1537709747.103981.1517680056.72C7A43E@webmail.messagingengine.com> User-Agent: Mutt/1.10.1 (2018-07-13) --PEIAKu/WMn1b1Hv9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --PEIAKu/WMn1b1Hv9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="0001-Call-fsync-after-writing-out-new-histfile.patch" >From 78b1df1329b2c7bb2b6e78e5b7d70be4bbf103e2 Mon Sep 17 00:00:00 2001 From: lilydjwg 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 --PEIAKu/WMn1b1Hv9--