open.2: Enhance rationale discussion for openat() and friends

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2014-12-12 08:45:17 +01:00
parent a3708b57a5
commit 54305f5b5f
1 changed files with 14 additions and 1 deletions

View File

@ -1314,11 +1314,24 @@ of the directory prefix given to
.BR open ()
could be changed in parallel with the call to
.BR open ().
Suppose, for example, that we wish to create the file
.I path/to/xxx.dep
if the file
.I path/to/xxx
exists.
The problem is that between the existence check and the file creation step,
.I path
or
.I to
(which might be symbolic links)
could be modified to point to a different location.
Such races can be avoided by
opening a file descriptor for the target directory,
and then specifying that file descriptor as the
.I dirfd
argument of
argument of (say)
.BR fstatat (2)
and
.BR openat ().
Second,