Curious situation with unlink() and open()

William Park opengeometry-FFYn/CNdgSA at public.gmane.org
Tue May 1 02:18:20 UTC 2012


On Mon, Apr 30, 2012 at 12:19:15PM -0400, Yanni Chiu wrote:
> On 30/04/12 11:31 AM, William Park wrote:
> >
> >I think the issue is, lock is applied after open(), not before.
> >But, you lock on file descriptor which open() gives you.
> 
> I think the issue is that it's a lock on writing the file (so the bits 
> don't get garbled by two processes writing at the same time). It's not
> a lock on removing the file entirely. As others have said, the two
> processes have to coordinate, whether or not the file can be removed.
> The write lock is not the right mechanism for this coordination - you
> need additional program logic (maybe another file).

Hmm... creating separate lock file (O_RDONLY|O_CREAT|O_EXCL) seems to
work, by forcing open() to fail for all subsequent attempts to get fd.
It's polluting the directory, but the code is only few lines more.
Thanks.
-- 
William
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list