Use flock () in sigaction handler

flock() is generally safe as a signal since it is a system call. Its semantics makes it difficult to implement it in different ways. This is not a POSIX list for functions that support async, since it is not at all on POSIX.

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

+5
source share
1 answer

According to @alk, answer in the subject :

We can develop our flock() function (its name may be async_flock() ). in this new function, we copy the contents of the lockf() source code and then make the following changes to get a safe asynchronous function:

  • replace __fcntl with fcntl : code must be compiled
  • replace __set_errno(<errno-define>) with errno = <errno-define> : you need to compile the code

  • replace the call with memset() with the appropriate settings struct fcntl = {0} : it needs to become async-signal persistence.

0
source

Source: https://habr.com/ru/post/946708/


All Articles