Re: [EXIM] off topic - NFS locking help required :)

Kezdőlap
Üzenet törlése
Válasz az üzenetre
Szerző: michael
Dátum:  
Címzett: exim-users, Peter.Galbavy
Tárgy: Re: [EXIM] off topic - NFS locking help required :)
> I have a need to lock a file and/or a whole directory on a shared
> NFS file system from a perl script. Can anyone refer me to a good,
> generic method that is reliable enough ? Speed is not of any real
> need, but consistency is. My guess is that exim-folks are likely
> to have "been there, done that" already - so I would appreciate
> pointers.


Quoting from open(2) on Linux:

       O_EXCL  When used with O_CREAT, if the file already exists
               it  is an error and the open will fail.  O_EXCL is
               broken on NFS file systems, programs which rely on
               it  for  performing  locking  tasks will contain a
               race  condition.   The  solution  for   performing
               atomic  file locking using a lockfile is to create
               a unique file on the same fs (e.g.,  incorporating
               hostname  and  pid), use link(2) to make a link to
               the lockfile and use stat(2) on the unique file to
               check  if  its  link count has increased to 2.  Do
               not use the return value of the link() call.


This algorithm is used e.g. by procmail.

Michael

--
*** Exim information can be found at http://www.exim.org/ ***