简体   繁体   中英

Use flock() in the sigaction handler

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.

Is it possible to use flock() in the sigaction handler without problems?

According to @alk answer in the following topic :

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:

  • replace __fcntl with fcntl : necessary to make the code compile
  • replace __set_errno(<errno-define>) with errno = <errno-define> : necessary to make the code compile

  • replace the call to memset() with appropriate assigments struct fcntl = {0} : necessary to have it become async-signal-save.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM