From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25894 invoked from network); 12 May 2006 23:24:20 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.1 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 12 May 2006 23:24:20 -0000 Received: (qmail 98484 invoked from network); 12 May 2006 23:24:12 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 12 May 2006 23:24:12 -0000 Received: (qmail 29057 invoked by alias); 12 May 2006 23:24:05 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10262 Received: (qmail 29047 invoked from network); 12 May 2006 23:24:05 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 12 May 2006 23:24:05 -0000 Received: (qmail 97453 invoked from network); 12 May 2006 23:24:05 -0000 Received: from vinc17.net8.nerim.net (HELO prunille.vinc17.org) (62.212.121.106) by a.mx.sunsite.dk with SMTP; 12 May 2006 23:24:04 -0000 Received: by prunille.vinc17.org (Postfix, from userid 501) id C48FE8F51EB; Sat, 13 May 2006 01:24:02 +0200 (CEST) Date: Sat, 13 May 2006 01:24:02 +0200 From: Vincent Lefevre To: zsh-users@sunsite.dk Subject: Re: File locking within zsh? Message-ID: <20060512232402.GB871@prunille.vinc17.org> Mail-Followup-To: zsh-users@sunsite.dk References: <87r7324zyh.fsf@asfast.com> <009101c673f7$06b3f090$6500000a@venti> <20060510171305.GA4116@prunille.vinc17.org> <009d01c67511$f91c8ed0$6500000a@venti> <20060512075401.GN4116@prunille.vinc17.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Mailer-Info: http://www.vinc17.org/mutt/ User-Agent: Mutt/1.5.11-vl-20060510 On 2006-05-12 15:40:30 -0400, Tim Writer wrote: > I'm not sure that the symlink() system call is guaranteed to be > atomic but link() is. OK for link(). The Linux open(2) man page says: O_EXCL When used with O_CREAT, if the file already exists it is an error and the open() will fail. In this context, a symbolic link exists, regardless of where it points to. O_EXCL is broken on NFS file systems; programs which rely on it for performing lock- ing tasks will contain a race condition. The solution for per- forming atomic file locking using a lockfile is to create a unique file on the same file system (e.g., incorporating host- name and pid), use link(2) to make a link to the lockfile. If link() returns 0, the lock is successful. Otherwise, use stat(2) on the unique file to check if its link count has increased to 2, in which case the lock is also successful. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / SPACES project at LORIA