lkml.org 
[lkml]   [2018]   [Apr]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Race-free unlinking of directory entries
On Mon, Apr 09, 2018 at 12:10:09PM +0200, Pali Rohár wrote:
> I do not think it is enough, specially in cases when hard links are in
> use. Example:
>
> fd = open("/a")
> link("/a", "/b")
> link("/a", "/c")
> unlink("/a")
>
> And now I want to call funlink for "fd". Which file should be unlinked?
> "/b" or "/c" or none or both?

'/a' as that is what fd refers to.

>
> Another example:
>
> fd = open("/a")
> link("/a", "/b")
> unlink("/a")
>
> Calling funlink for fd should unlink "/b" or it should fail?

It should fail, as '/a' doesn't refer to name that is visible in the
namespace.

> And another example:
>
> fd = open("/a")
> rename("/a", "/b")
>
> What should funlink do for fd now?

remove the directory entry refering to '/b' as that is what fd refers
to.

> Note that there is difference which symlink is shown in /proc/<pid>/fd
> between last two examples -- even those two examples results in the same
> state (if there is no race). For last example <fd> points to "/b", for
> previous <fd> points to "/a (deleted)".

Yes, that is fully expected.

\
 
 \ /
  Last update: 2018-04-09 12:24    [W:0.505 / U:0.064 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site