Curious situation with unlink() and open()

William Park opengeometry-FFYn/CNdgSA at public.gmane.org
Mon Apr 30 15:31:32 UTC 2012


If file already exists, then I can accept it.  But, if file does
not exist, then logic would go something like...

fd1 creates a new file, but later on, decides it's notneeded.
Since it was the one who created the file and has exclusive lock

on it, fd1 unlink() the file and close(fd1).  In between fd1's
open() and unlink(), fd2 sees the file and happily does I/O
oblivious that what fd1 did.  After close(fd2), all the work
of fd2 is gone, even though fd2's work happened after close(fd1).

  

I think the issue is, lock is applied after open(), not before.
But, you lock on file descriptor which open() gives you.
-- 
William


----- Original Message -----
> From: D. Hugh Redelmeier <hugh at mimosa.com>
> To: tlug-lxSQFCZeNF4 at public.gmane.org
> Cc: 
> Sent: Monday, April 30, 2012 9:10:11 AM
> Subject: Re: [TLUG]: Curious situation with unlink() and open()
> 
>|  From: William Park <opengeometry-FFYn/CNdgSA at public.gmane.org>
> 
> | How do you keep what you did with fd2?
> 
> If you want to keep it, don't delete the file.  Pretty simple, really.
> 
> What is the logic of the program such that it would delete a file that
> you don't want deleted?  That's not a rhetorical question: if you can
> explain the logic, you can probably code it.
> 
> One hacky solution to the problem as you posed it (not your real
> problem!) would be to create a (second) hard link to the file.  Then
> deleting the first link does not cause the file to be deleted.
> --
> 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
> 
--
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