在sigaction处理程序中使用flock() [英] Use flock() in the sigaction handler
问题描述
flock()
通常是异步信号安全的,因为它是系统调用.它的语义使得很难以不同的方式来实现它.它不在POSIX的异步信号安全功能的列表中,因为它根本不在POSIX中.
flock()
is generally async-signal-safe because it is a system call. Its semantics make it hard to implement it differently. It is not in the POSIX's list of async-signal-safe functions because it is not in POSIX at all.
是否可以在sigaction处理程序中使用flock()
而不出现问题?
Is it possible to use flock()
in the sigaction handler without problems?
推荐答案
根据以下
我们可以开发属性flock()
函数(其名称可能为async_flock()
).我们在此新函数中复制原始lockf()
代码的内容,然后进行以下更改以获取异步信号安全函数:
We can develop our property flock()
function (its name could be async_flock()
). we copy in this new function the content of the origin lockf()
code and then we make the following changes in order to get an async-signal-safe function:
- 将
__fcntl
替换为fcntl
:代码编译所必需的 -
将
__set_errno(<errno-define>)
替换为errno = <errno-define>
:代码编译所必需的
- replace
__fcntl
withfcntl
: necessary to make the code compile replace
__set_errno(<errno-define>)
witherrno = <errno-define>
: necessary to make the code compile
用适当的配置struct fcntl = {0}
替换对memset()
的调用:必须使其成为异步信号保存.
replace the call to memset()
with appropriate assigments struct fcntl = {0}
: necessary to have it become async-signal-save.
这篇关于在sigaction处理程序中使用flock()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!