Linux 似乎获得了很多 *at 调用?这些的动机是什么?
Linux seems to have acquired a lot of *at calls? What is the motivation for these?
我注意到 Linux 现在有 renameat
、fstatat
、openat
和其他各种允许您指定文件相关路径的调用描述符,而不是像通常情况下那样相对于进程的当前工作目录来解释它们。
为什么要添加这些调用?似乎大多数系统调用的 at
版本都具有路径名参数,因此必须有一个非常引人注目的用例。但是我想不出来是什么。
所有这些 *at
例程都是作为 POSIX 部分介绍的。如果深入研究 openat routine 的基本原理部分,您会发现以下段落:
The purpose of the openat() function is to enable opening files in directories other than the current working directory without exposure to race conditions. Any part of the path of a file could be changed in parallel to a call to open(), resulting in unspecified behavior. By opening a file descriptor for the target directory and using the openat() function it can be guaranteed that the opened file is located relative to the desired directory.
换句话说,这是一种安全措施。
我注意到 Linux 现在有 renameat
、fstatat
、openat
和其他各种允许您指定文件相关路径的调用描述符,而不是像通常情况下那样相对于进程的当前工作目录来解释它们。
为什么要添加这些调用?似乎大多数系统调用的 at
版本都具有路径名参数,因此必须有一个非常引人注目的用例。但是我想不出来是什么。
所有这些 *at
例程都是作为 POSIX 部分介绍的。如果深入研究 openat routine 的基本原理部分,您会发现以下段落:
The purpose of the openat() function is to enable opening files in directories other than the current working directory without exposure to race conditions. Any part of the path of a file could be changed in parallel to a call to open(), resulting in unspecified behavior. By opening a file descriptor for the target directory and using the openat() function it can be guaranteed that the opened file is located relative to the desired directory.
换句话说,这是一种安全措施。