gpt4 book ai didi

c - stat(2) 和 EINTR

转载 作者:行者123 更新时间:2023-12-02 01:12:56 26 4
gpt4 key购买 nike

有一些系统调用支持的 I/O 函数(我最近发现至少两个:stat()mkdir() 但几乎可以肯定还有更多)根据 POSIX,可能的 errno 值中没有 EINTR,但肯定可能由于磁盘繁忙或网络安装的文件系统而阻塞。

我怀疑可能存在稍微不符合 POSIX 的实现从这些函数返回 EINTR,尤其是在网络文件系统上。这有多大可能?有必要检查 stat() 的 EINTR 或者我可以绝对确定此系统调用不会被中断吗?

更新正如答案和评论中所述,POSIX 2.3 允许执行以下操作:

Implementations may generate error numbers listed here under circumstances other than those described, if and only if all those error conditions can always be treated identically to the error conditions as described in this volume of POSIX.1-2017. Implementations shall not generate a different error number from one required by this volume of POSIX.1-2017 for an error condition described in this volume of POSIX.1-2017, but may generate additional errors unless explicitly disallowed for a particular function.

但是有一件重要的事情:EINTR实际上不是一个错误情况(从任何角度来看它都不是失败),并且它的正确处理将总是需要一些特殊的代码。

示例来说明我的意思:让我们想象 stat() 从 NFS 处理程序返回 POSIX 未记录的 ECONNRESET。此错误代码没有记录,但不会造成任何损害:我们知道系统调用由于某种原因失败,并且我们的错误处理程序可能不关心到底发生了什么错误,因为所有错误都意味着失败。 EINTR 是完全不同的故事。

最佳答案

Error Numbers 的第 2.3 节中在 POSIX.1-2017 的“系统接口(interface):一般信息”部分,你可以发现:

Implementations may support additional errors not included in this list, may generate errors included in this list under circumstances other than those described here, or may contain extensions or limitations that prevent some errors from occurring.

The ERRORS section on each reference page specifies which error conditions shall be detected by all implementations ("shall fail") and which may be optionally detected by an implementation ("may fail"). If no error condition is detected, the action requested shall be successful. If an error condition is detected, the action requested may have been partially performed, unless otherwise stated.

Implementations may generate error numbers listed here under circumstances other than those described, if and only if all those error conditions can always be treated identically to the error conditions as described in this volume of POSIX.1-2017. Implementations shall not generate a different error number from one required by this volume of POSIX.1-2017 for an error condition described in this volume of POSIX.1-2017, but may generate additional errors unless explicitly disallowed for a particular function.

Each implementation shall document, in the conformance document, situations in which each of the optional conditions defined in POSIX.1-2017 is detected. The conformance document may also contain statements that one or more of the optional error conditions are not detected.

在我看来,第一个引用的段落允许在您描述的情况下生成 EINTR

关于c - stat(2) 和 EINTR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59205655/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com