The explanation at
openat is needed, reads in part:
openat() allows an application to avoid race conditions that could occur when using open() to open files in directories other than the current working directory. These race conditions result from the fact that some component of the directory prefix given to open() could be changed in parallel with the call to open(). Suppose, for example, that we wish to create the file path/to/xxx.dep if the file path/to/xxx exists. The problem is that between the existence check and the file creation step, path or to (which might be symbolic links) could be modified to point to a different location.
I don't understand why this race is a problem. If an app wants to check for the existence of some file and if so, create a different file, then, of course these are two steps, and the app should and can ensure that nothing interferes in between. Only if a single call to
open() could cause a race condition, might some other syscall, such as
openat() be needed. Otherwise, this is not for syscalls to solve, but it is an application's responsibility.
What am I not understanding here?