fdm: add support for managing signals

Add fdm_signal_add() and fdm_signal_del(). Signals added to the fdm
will be monitored, and the provided callback called as “soon as
possible” from the main context (i.e not from the signal handler
context).

Monitored signals are *blocked* by default. We use epoll_pwait() to
unblock them while we’re polling. This allows us to do race-free
signal detection.

We use a single handler for all monitored signals; the handler simply
updates the signal’s slot in a global array (sized to fit SIGRTMAX
signals).

When epoll_pwait() returns EINTR, we loop the global array. The
callback associated with each signal that fired is called.
This commit is contained in:
Daniel Eklöf 2021-02-10 16:17:36 +01:00
parent ac46e58448
commit cf1335f258
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 147 additions and 26 deletions

View file

@ -35,7 +35,7 @@ async_write(int fd, const void *data, size_t len, size_t *idx)
}
bool
fdm_add(struct fdm *fdm, int fd, int events, fdm_handler_t handler, void *data)
fdm_add(struct fdm *fdm, int fd, int events, fdm_fd_handler_t handler, void *data)
{
return true;
}