Quantcast
Channel: User Sourav Kannantha B - Stack Overflow
Viewing all articles
Browse latest Browse all 60

Is there a safeunlink syscall in Unix?

$
0
0

There is an unlink syscall in Unix, which takes a path as argument, and unlinks that path from inode.

Suppose this case. I will open a file, access the contents, and then decide that it should be unlinked. By this time, a different process has replaced that path with a different file for some reason. Now if I call unlink with that path, it will unlink the wrong file, and probably confusing the other process.

Hence, is there way where I can pass the inode number along with the path to (safe)unlink syscall so that it can atomically check if the path refers to the same inode and then unlink, if not report an errno or do a no-op?

Is there a way to do that in Unix? If not why is it left out? Is such a syscall not necessary for some reason? Can it be emulated using combination of other syscalls? Is it missed out by mistake?


Viewing all articles
Browse latest Browse all 60

Trending Articles