aboutsummaryrefslogtreecommitdiff
path: root/reaper.c (unfollow)
Commit message (Collapse)AuthorLines
2021-02-12reaper: monitor SIGCHLD using the FDM instead of via a signalfdDaniel Eklöf-86/+28
In addition to letting the FDM do the low-level signal watching, this patch also fixes a bug; multiple SIGCHLDs, be it delivered either through a signal, or via a signalfd, can be coalesced, like all signals. This means we need to loop on waitpid() with WNOHANG until there are no more processes to reap. This in turn requires a small change to the way reaper callbacks are implemented. Previously, the callback was allowed to do the wait(). This was signalled back to the reaper through the callback’s return value. Now, since we’ve already wait():ed, the process’ exit status is passed as an argument to the reaper callback. The callback for the client application has been updated accordingly; it sets a flag in the terminal struct, telling term_destroy() that the process has already been wait():ed on, and also stores the exit status.
2021-02-11reaper: monitor SIGCHLD using the FDM instead of via a signalfdDaniel Eklöf-85/+27
In addition to letting the FDM do the low-level signal watching, this patch also fixes a bug; multiple SIGCHLDs, be it delivered either through a signal, or via a signalfd, can be coalesced, like all signals. This means we need to loop on waitpid() with WNOHANG until there are no more processes to reap. This in turn requires a small change to the way reaper callbacks are implemented. Previously, the callback was allowed to do the wait(). This was signalled back to the reaper through the callback’s return value. Now, since we’ve already wait():ed, the process’ exit status is passed as an argument to the reaper callback. The callback for the client application has been updated accordingly; it sets a flag in the terminal struct, telling term_destroy() that the process has already been wait():ed on, and also stores the exit status.
2021-01-21reaper: remove child from list *before* calling the user provided callbackDaniel Eklöf-9/+11
The user provided callback may call reaper_del(), in which case we will crash when we also try to remove the child from the list. Remove it from the list before the callback means reaper_del() (if called by the callback) will just loop through the entire list without finding the pid and thus do nothing.
2021-01-21reaper: add reaper_del() - pid is no longer watched/monitored after thisDaniel Eklöf-0/+11
2021-01-21reaper: add optional callbackDaniel Eklöf-18/+34
When calling ‘reaper_add()’, the caller can provide a callback. If non-NULL, the reaper will call the callback to handle the actual reaping. If the callback is NULL, or if it returns false, the reaper reaps the child process.
2021-01-16debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes-2/+2
2021-01-16Print stack trace on assert() failure or when calling fatal_error()Craig Barnes-1/+2
Note: this uses the __sanitizer_print_stack_trace() function from the AddressSanitizer runtime, so it only works when AddressSanitizer is in use.
2021-01-12reaper: remove child from list *before* calling the user provided callbackDaniel Eklöf-9/+11
The user provided callback may call reaper_del(), in which case we will crash when we also try to remove the child from the list. Remove it from the list before the callback means reaper_del() (if called by the callback) will just loop through the entire list without finding the pid and thus do nothing.
2021-01-12reaper: add reaper_del() - pid is no longer watched/monitored after thisDaniel Eklöf-0/+11
2020-12-26reaper: add optional callbackDaniel Eklöf-18/+34
When calling ‘reaper_add()’, the caller can provide a callback. If non-NULL, the reaper will call the callback to handle the actual reaping. If the callback is NULL, or if it returns false, the reaper reaps the child process.
2020-10-10selection: use appropriate check for PRIMARY pasteSergey Nazaryev-50/+79
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-15Fix some spelling mistakesCraig Barnes-1/+1
2020-08-09Handle allocation failures explicitly in *_init() functionsCraig Barnes-2/+8
2020-08-08Convert most dynamic allocations to use functions from xmalloc.hCraig Barnes-1/+2
2020-05-21reaper: disable debug loggingDaniel Eklöf-1/+1
2020-05-21reaper: new module, uses a signalfd to wait() on child processesDaniel Eklöf-0/+142
Use a signalfd to listen for SIGCHLD signals. When we receive a SIGCHLD over the signalfd, reap all dead children by looping over all registered child PIDs and call waitpid(WNOHANG) on them.