The trouble with symbolic links
The trouble with symbolic links
Posted Jul 8, 2022 1:20 UTC (Fri) by mpr22 (subscriber, #60784)In reply to: The trouble with symbolic links by zaitseff
Parent article: The trouble with symbolic links
- Any time you access a file without knowing which data directory to use, search for your preferred data directory with open() and fstat().
- If you find one of your desired directories, retain the file descriptor as well as the pathname, and use openat() with the file descriptor for all further activities relating to your preferred data directory.
- If you don't find any of the desired data directories, then don't retain the result at all; next time you try to access a file, start fresh from step 1.
Safely creating the directory if it doesn't exist is still kind of a pain in the neck, because you can't combine the operations of "make a directory" and "open a file descriptor pointing to the directory" into a single indivisible syscall.
