zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: Re: skip rewriting history if exiting due to signal
Date: Sun, 17 Oct 2004 17:21:18 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.61.0410171652500.8058@toltec.zanshin.com> (raw)
In-Reply-To: <20041017194842.GA26158@blorf.net>

On Sun, 17 Oct 2004, Wayne Davison wrote:

> Here's a patch that makes the savehistfile() function use a temporary
> file whenever it writes out the whole file from the start (rather than
> overwriting the existing file).  This could be controversial if someone
> out there has a symlink for their history file

Hm.

- It requires a writable directory rather than merely a writable histfile.
  Perhaps fall back to the old behavior if the directory is not writable?
  Similarly, perhaps detect when the histfile is a symlink and fall back?

- You haven't tested for failure of unlink() [though I'm not sure what the
  response to such failure would be ... except see below about O_EXCL].

- You haven't tested for failure of rename() -- and note that rename() may 
  falsely report failure in the event of certain NFS errors.

> The naming scheme I chose to use was to write out the history data using
> the name $HISTFILE.$$ since this naming idiom is already used for a
> temporary file name when acquiring the $HISTFILE.LOCK lock file

I wasn't aware of that latter; it should be changed.  Using the PID as a 
disambiguator is also not safe when NFS is involved (two shells with the 
same PID on different hosts may be accessing the histfile in the same 
NFS-mounted home directory at the same time, unlikely as that seems).

At the very least you should be open()ing with O_EXCL, and be prepared to 
recover if that fails (although O_EXCL is not reliable over NFS).

> If folks think that $HISTFILE.new is a better choice, it would be easy 
> to change.

No, that'd definitely be worse (even more likely to have conflict when 
multiple shells are rewriting the history), not better.


  reply	other threads:[~2004-10-18  0:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-01 19:36 Wayne Davison
2004-10-17 19:48 ` Wayne Davison
2004-10-18  0:21   ` Bart Schaefer [this message]
2004-10-18  5:00     ` Wayne Davison
2004-10-18 19:36       ` Improved HISTFILE locking Wayne Davison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.61.0410171652500.8058@toltec.zanshin.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).