The explanation at


about why 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?

  • Issues specific to programming and software development are off topic, see On-Topic. Try Stack Overflow but please first read How do I ask a good question?. You can flag your question and ask a moderator to migrate it.
    – DavidPostill
    Feb 16, 2016 at 13:31
  • @DavidPostill I know about StackOverflow, I specifically chose to post here, because StackOverflow is for questions like this "I am trying to program xyz, here is what I tried, it does not work". The above question is not like that, it is not a programming question.
    – user322908
    Feb 18, 2016 at 5:54
  • It is a programming issue - you are asking for an explanation of how and why some API calls work.
    – DavidPostill
    Feb 18, 2016 at 8:39
  • @DavidPostill OK I moved it, I hope they don't say there "this question is not a programming question".
    – user322908
    Feb 18, 2016 at 10:13

1 Answer 1


The race is referring only to files that are not in the current directory. The relative path that you are passing to openat() could contain a symlink that points to a different directory than the one you are expecting.

If you only use open() with files in the current directory (after making sure you are where you want to be), you avoid this problem.

  • 1
    I am sorry, but you are just restating what the man page says, not answering any of my question. I know the symptoms of the race, you don't have to explain it to me. I don't understand why isn't the application expected to deal with the race, and why a separate syscall is needed.
    – user322908
    Feb 16, 2016 at 11:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .