冗余 Linux 内核系统调用

发布于 2024-07-08 21:33:06 字数 330 浏览 6 评论 0原文

我目前正在开发一个项目,该项目挂钩各种系统调用并将内容写入日志,具体取决于调用的是哪个系统调用。 因此,例如,当我更改文件的权限时,我会向日志文件写入一个小条目来跟踪旧权限和新权限。 然而,我在确定我应该观看的确切位置时遇到了一些困难。 对于上面的示例,strace 告诉我“chmod”命令使用系统调用 sys_fchmodat()。 但是,还有 sys_chmod() 和 sys_fchmod()。

我确信内核开发人员知道他们在做什么,但我想知道:所有这些(看似)冗余的系统调用的意义是什么?对于哪些系统调用的用途有什么规则吗? (即“at”系统调用或前缀为“f”的系统调用是否意味着执行特定操作?)

I'm currently working on a project that hooks into various system calls and writes things to a log, depending on which one was called. So, for example, when I change the permissions of a file, I write a little entry to a log file that tracks the old permission and new permission. However, I'm having some trouble pinning down exactly where I should be watching. For the above example, strace tells me that the "chmod" command uses the system call sys_fchmodat(). However, there's also a sys_chmod() and a sys_fchmod().

I'm sure the kernel developers know what they're doing, but I wonder: what is the point of all these (seemingly) redundant system calls, and is there any rule on which ones are used for what? (i.e. are the "at" syscalls or ones prefixed with "f" meant to do something specific?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静若繁花 2024-07-15 21:33:06

历史记录:-)

一旦创建了系统调用,就无法更改,因此当需要新功能时,就会创建新的系统调用。 (当然,这意味着创建新的系统调用之前有一个非常高的门槛)。

History :-)

Once a system call has been created it can't ever be changed, therefore when new functionality is required a new system call is created. (Of course this means there's a very high bar before a new system call is created).

薄荷→糖丶微凉 2024-07-15 21:33:06

是的,有一些命名规则。

  • chmod 接受一个文件名,而 fchmod 接受一个文件描述符。 stat 与 fstat 相同。
  • fchmodat 采用文件描述符/文件名对(目录的文件描述符和目录中文件名的文件名)。 其他 *at 调用也一样; 请参阅 http://kerneltrap.org/man/linux/man2/openat 的注释部分.2 进行解释。

Yes, there are some naming rules.

  • chmod takes a filename, while fchmod takes a file descriptor. Same for stat vs fstat.
  • fchmodat takes a file descriptor/filename pair (file descriptor for the directory and filename for the file name within the directory). Same for other *at calls; see the NOTES section of http://kerneltrap.org/man/linux/man2/openat.2 for an explanation.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文