aboutsummaryrefslogtreecommitdiff
path: root/fdm.c (unfollow)
Commit message (Collapse)AuthorLines
2025-07-21fdm: when logging signal related errors, include the signal nameDaniel Eklöf-6/+24
Since sigabbrev_np() is GNU only, provide a fallback function that returns "SIG<signo>" when sigabbrev_np() doesn't exist (for example, on FreeBSD).
2022-02-12Explicitly initialize sigaction::sa_mask members with sigemptyset(3)Craig Barnes-0/+2
Not doing so before calling sigaction(3) is "undefined" according to POSIX[1]: > Applications shall call either sigemptyset() or sigfillset() at least > once for each object of type sigset_t prior to any other use of that > object. If such an object is not initialized in this way, but is > nonetheless supplied as an argument to any of pthread_sigmask(), > sigaction(), sigaddset(), sigdelset(), sigismember(), sigpending(), > sigprocmask(), sigsuspend(), sigtimedwait(), sigwait(), or > sigwaitinfo(), the results are undefined. The use of designated initializers means that sa_mask members were still being initialized, but sigset_t is an opaque type and implicit initialization doesn't necessarily produce the same results as using sigemptyset(3) (although it typically does on most implementations). [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaddset.html
2021-05-21fdm: always check for signals after epoll_pwait(), not only on EINTRDaniel Eklöf-14/+18
This fixes an issue where we, at least on FreeBSD, sometimes get stuck in epoll_pwait() after the shell has exited. It turned out to be because the SIGCHLD signal was delivered at the same time FDs were made readable/writeable. I.e. epoll_pwait() returned a non-zero value even though it should have been interrupted by the SIGCHLD. To avoid having to search the entire signal array *every time* epoll_pwait() returns, add a flag that is set in the signal handler. This tells the FDM to scan the signal array after returning from epoll_pwait().
2021-02-21spawn/slave: restore signal mask after forkDaniel Eklöf-1/+0
slave: no need to restore signal handlers; they are automatically restored as long as they are not SIG_IGN (which they never are in foot). spawn(): restore signal mask after fork. This fixes an issue where a terminal spawned with ctrl+shift+n did not terminate when its shell exited. Closes #366
2021-02-12fdm: add support for managing signalsDaniel Eklöf-23/+140
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.
2021-02-11fdm: add support for managing signalsDaniel Eklöf-21/+141
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.
2021-02-10Convert all but 2 remaining uses of xassert(false) to BUG("...")Craig Barnes-6/+2
2021-02-09Convert some uses of xassert(false) to BUG("some error message")Craig Barnes-1/+1
2021-01-16debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes-9/+9
2021-01-16Print stack trace on assert() failure or when calling fatal_error()Craig Barnes-1/+1
Note: this uses the __sanitizer_print_stack_trace() function from the AddressSanitizer runtime, so it only works when AddressSanitizer is in use.
2020-12-04fdm: do *not* keep polling on EINTRDaniel Eklöf-5/+4
This fixes an issue where foot --server did not exit on SIGINT. This happened because we never returned out from fdm_poll(), and thus we never saw ‘aborted’ being set.
2020-11-26fdm: keep polling on EINTRDaniel Eklöf-4/+5
2020-10-10selection: use appropriate check for PRIMARY pasteSergey Nazaryev-175/+36
Assume it could be a copy-paste typo. We should check PRIMARY, not CLIPBOARD. Without this fix, we can't use PRIMARY until we copy anything to CLIPBOARD.
2020-08-23Cast printf formatter %p arguments to void*Daniel Eklöf-8/+15
2020-08-08Convert most dynamic allocations to use functions from xmalloc.hCraig Barnes-0/+10
2020-01-10fdm: fix log messageDaniel Eklöf-1/+1
2020-01-10fdm: verify FDs are non-blocking (debug builds only)Daniel Eklöf-0/+10
2020-01-04fdm: add hook prioritiesDaniel Eklöf-13/+55
There are now three hook priorities: low, normal, high. High priority hooks are executed *first*. Normal next, and last the low priority hooks. The renderer's terminal refresh hook now runs as a normal priority hook.
2020-01-04fdm: add support for hooksDaniel Eklöf-0/+49
Hooks are functions executed just before going into a poll(). Or just after executing all FD handlers, if you like.
2019-12-15fdm: close fd even if we didn't find it in our listDaniel Eklöf-0/+1
This behavior is debatable, but helps in error handling where we're removing a bunch of descriptors where not all of them have been added to the FDM yet.
2019-11-17tllist: is now an external "library", so use <> includesDaniel Eklöf-1/+2
2019-11-02fdm: invert check to get rid of one level of indentationDaniel Eklöf-13/+14
2019-11-02fdm: add fdm_event_add() and fdm_event_del()Daniel Eklöf-1/+52
These functions allow users to modify already registered FDs, to add or remove events they are interested in.
2019-11-02fdm: bug: 'ret' was renamed to 'r', and replaced with another 'ret'Daniel Eklöf-1/+1
2019-11-02fdm: rename struct fd -> struct handlerDaniel Eklöf-11/+11
2019-11-02fdm: fdm_destroy(): assert deferred delete list is emptyDaniel Eklöf-0/+2
2019-11-02fdm: purge deferred delete list also when handler failsDaniel Eklöf-5/+8
2019-11-02fdm: fdm_poll(): disallow nested callsDaniel Eklöf-0/+6
2019-11-01fdm: don't free FD data that may be referenced by epoll return dataDaniel Eklöf-9/+59
It is perfectly possible, and legal, for a FDM handler to delete another handler. The problem however is when the epoll returned array of FD events contain the removed FD handler *after* the handler that removed it. That is, if the epoll returned array is: [FD=13, FD=37] and the handler for FD=13 removes FD=37, then given the current implementation, the FD user data (our handler callback etc) will point to a free:d address. Add support for this situation by deferring FD handler removal *when called from another handler*. This is done by "locking" the FDM struct before looping the handlers for FDs with events (and unlocking afterwards). In fdm_del(), we check if the FDM has been locked, in which case the FD is marked as deleted, and put on a deferred list. But not *actually* deleted. Meanwhile, in the FDM poll function, we skip calling handlers for marked-for-deletion FDs. Then, when all FDs have been processed, we loop the deferred list and finally deletes the FDs for real.
2019-10-27fdm: use the FDM's poll loopDaniel Eklöf-0/+124