4 ms·
in this situation you can do a stat on the file descriptor after you have opened the file to ensure that it is not a symlink. some of the races with the filesys
by benmmurphy 10y ago
in this situation you can do a stat on the file descriptor after you have opened the file to ensure that it is not a symlink. some of the races with the filesystem can be fixed using the file descriptor family of functions instead of the path family of functions.
- leni536 10y agoHow do you get a fd for the link and not the linked file?
- loeg 10y agoThere is the non-standard O_NOFOLLOW.
- adrianratnapala 10y agoCan you not do an ordinary open without O_NOFOLLOW and then lstat the filename?
- DblPlusUngood 10y agoWhy do you say "non-standard"? O_NOFOLLOW is specified by POSIX.
- loeg 10y agoThe Linux manual page is a little misleading, and I didn't dig further into POSIX. Mea culpa. O_NOFOLLOW If pathname is a symbolic link, then the open fails. This is a FreeBSD extension, which was added to Linux in version 2.1.126. Symbolic links in earlier components of the pathname will still be followed. See also O_PATH below. ... The O_CLOEXEC, O_DIRECTORY, and O_NOFOLLOW flags are not specified in POSIX.1-2001, but are specified in POSIX.1-2008.