Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: File locking within zsh?



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 <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA



Messages sorted by: Reverse Date, Date, Thread, Author