4 ms·
The very first example ("mv -T" to retarget a symlink, something I didn't know about and that the manpage is silent on) is not atomic! The symlink(2) syscall w
by ajross 17y ago
The very first example ("mv -T" to retarget a symlink, something I didn't know about and that the manpage is silent on) is not atomic! The symlink(2) syscall will not overwrite an existing directory entry. You have to call unlink(2) first, which opens a race.
That doesn't mean this trick is useless, but calling it "atomic" is wrong, and opens up the possibility of bugs (likely security holes, even) if someone actually needs atomicity.
- bshep 17y agoTo change a symlink I use: ln -snf NEW_SOURCE TARGET
- ajross 17y agoWhich works fine, but is still not atomic. To be clear, saying something is "atomic" means that there is no way for another process to see the process in an intermediate state (in the example in the article: a missing or incorrect symlink to a deployed web application). Underneath the hood, the /bin/ln program still needs to call unlink() on the path first, so there is a short period of time during which the desired link isn't present. So software written to assume that the link is always valid (for example, because its author was told that the update was atomic) will have hidden bugs. This kind of tool merely runs really fast. The race condition is still there.
- bshep 17y agoI never said it was atomic ;-) just that i use that method rather than mv. I mainly use it when i'm updating apps or SDks to newer versions and want to keep the old ones around just in case.
- bretthoerner 17y ago> something I didn't know about and that the manpage is silent on It's specific to GNU Coreutils mv(1).
- deleted 17y ago[deleted]