4 ms·
I can't think of any case, except if you are too lazy to pass a file descriptor to another process, and its easier to pass the name (which cannot be ruled out,
by justincormack 13y ago
I can't think of any case, except if you are too lazy to pass a file descriptor to another process, and its easier to pass the name (which cannot be ruled out, it is easier!). You can't safely close and reopen the file, or it might have been modified.
There is still a possibility that an attacker opens the file before you unlink it and starts writing to it, which O_TMPFILE gets rid of as it never has a name so can never be opened.
- qu4z-2 13y agoDoes every program which accepts filenames also accept file descriptors? I can definitely see the use of having a name to pass around.
- caf 13y agoThe case where a name is required is where you want to rename or link the temporary file to a new, permanent name in the filesystem.
- skybrian 13y agoIt's also useful for debugging. If the file has a name, you can look at the file while the program is stopped in a debugger.
- mortehu 13y agoHow about whenever you're writing a non=temporary file? I do this all the time: 1. Create temporary file in the same directory as the target path. 2. Write and fsync the temporary file 3. Rename the temporary file to the target filename Oh, and on Linux you can open even deleted files by using /proc/<N>/fd/<M>. It may look like a symlink, but it's not.
- justincormack 13y agoOK that's a good reason!
- justincormack 13y agoYou can create files form the fd you get from O_TMPFILE it turns out http://lwn.net/SubscriberLink/562488/3c6d56bef275c0b4/ http://lwn.net/SubscriberLink/562488/3c6d56bef275c0b4/