5 ms·
Oh no mkstemp is already obsolete (in Linux), now we have O_TMPFILE [1] for creating temporary files that do not even have names... [1] https://lwn.net/Article
by justincormack 13y ago
Oh no mkstemp is already obsolete (in Linux), now we have O_TMPFILE [1] for creating temporary files that do not even have names...
[1] https://lwn.net/Articles/557314/ https://lwn.net/Articles/557314/
- masklinn 13y agoI don't think that makes mkstemp obsolete as it may be important to have named temp files. (and of course though there is a slight race you can unlink the file you get through mkstemp while keeping it open, that seems to be the strategy used by python's tempfile.TemporaryFile)
- justincormack 13y agoI 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/
- asveikau 13y agoEven ignoring the fact that these are not exactly the same... How does introducing a new interface necessarily "obsolete" the old one? Particularly when the old one is part of a standard, and the new one is not.