poller: Raise signals through self-pipe

Signal handling relied on poll(2) being interrupted by signals, followed
by a check for signal handlers flagging a signal as received. This only
allowed signals that were received during poll(2) to be handled
correctly.

Implement the usual self-pipe implementation, where signal handlers
write an arbitrary byte to a polled file descriptor to ensure proper
level-triggered signal handling.
This commit is contained in:
Kenny Levinsen 2020-09-18 15:06:29 +02:00
parent fb5743971c
commit 6747c5f3f8
3 changed files with 151 additions and 110 deletions

View file

@ -71,10 +71,11 @@ struct poller {
struct linked_list signals;
struct linked_list fds;
int signal_fds[2];
struct pollfd *pollfds;
size_t pollfds_len;
size_t fd_event_sources;
bool pollfds_dirty;
bool dirty;
};
/**
@ -96,7 +97,7 @@ struct poll_impl {
* Initializes the poller. The poller must be torn down with poller_finish when
* it is no longer needed.
*/
void poller_init(struct poller *poller);
int poller_init(struct poller *poller);
/**
* De-initializes the poller. This destroys all remaining event sources and