reaper: new module, uses a signalfd to wait() on child processes

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.
This commit is contained in:
Daniel Eklöf 2020-05-21 20:15:10 +02:00
parent 5600cc68c0
commit f49742ebba
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 161 additions and 0 deletions

6
main.c
View file

@ -21,6 +21,7 @@
#include "config.h"
#include "fdm.h"
#include "reaper.h"
#include "render.h"
#include "server.h"
#include "shm.h"
@ -353,6 +354,7 @@ main(int argc, char *const *argv)
conf.hold_at_exit = hold;
struct fdm *fdm = NULL;
struct reaper *reaper = NULL;
struct wayland *wayl = NULL;
struct renderer *renderer = NULL;
struct terminal *term = NULL;
@ -378,6 +380,9 @@ main(int argc, char *const *argv)
if ((fdm = fdm_init()) == NULL)
goto out;
if ((reaper = reaper_init(fdm)) == NULL)
goto out;
if ((wayl = wayl_init(&conf, fdm)) == NULL)
goto out;
@ -429,6 +434,7 @@ out:
shm_fini();
render_destroy(renderer);
wayl_destroy(wayl);
reaper_destroy(reaper);
fdm_destroy(fdm);
config_free(conf);