From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by melb.werple.net.au (8.7.5/8.7.3) with ESMTP id HAA27010 for ; Thu, 11 Apr 1996 07:28:06 +1000 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id RAA19896; Wed, 10 Apr 1996 17:21:27 -0400 (EDT) Resent-Date: Wed, 10 Apr 1996 17:21:27 -0400 (EDT) From: Zoltan Hidvegi Message-Id: <199604102121.XAA08127@bolyai.cs.elte.hu> Subject: Re: History file locking? To: A.Main@dcs.warwick.ac.uk (Zefram) Date: Wed, 10 Apr 1996 23:21:27 +0200 (MET DST) Cc: zsh-workers@math.gatech.edu (zsh-workers) In-Reply-To: <20845.199604101250@stone.dcs.warwick.ac.uk> from Zefram at "Apr 10, 96 01:50:13 pm" Organization: Dept. of Comp. Sci., Eotvos University, Budapest, Hungary Phone: (36 1)2669833 ext: 2667, home phone: (36 1) 2752368 X-Mailer: ELM [version 2.4ME+ PL15 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Resent-Message-ID: <"5HIjz3.0.os4.MP2Rn"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/913 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu > >Also things get quite complicated when the history file is on an NFS volume. > >Probaly some dot-locking method similar to the one used by sendmail & co > >should be used. > > I wouldn't bother -- it's only a history file. lockf() (and fcntl()) > locking work over NFS anyway; it's only flock() that doesn't. O_EXCL > isn't reliable over NFS, which makes .lock locking rather pointless. lockf() should work on NFS, but on many systems it doesn't. But properly implemented .lock works: 1. create a temporary lock file 2. link the temporary lock to the real lock. If the link succeeds, stat the temporary lock file. It its link count is 2 the locking really succeded, so remove the temp lock. This stat trick should work even on NFS. If the link fails, check the validity of the lock (the lock file should contain the PID of the locking process) using kill(0, lock_pid). If the lock is invalid, remove it and repeat step 2. That works on all systems without configure checks. Configure check for a working lock method is not simple. The checks should be done using all of the possible filesystems which zsh may use. Procmail has a test for that, but I one managed to crach a Solaris machine with it running is as an ordinal user. Bye, Zoltan