reaper: add optional callback

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.
This commit is contained in:
Daniel Eklöf 2020-12-26 01:26:54 +01:00
parent d778dc3d2a
commit 3c6789fb8b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 40 additions and 21 deletions

View file

@ -1,5 +1,6 @@
#pragma once
#include <stdbool.h>
#include <sys/wait.h>
#include "fdm.h"
@ -9,4 +10,6 @@ struct reaper;
struct reaper *reaper_init(struct fdm *fdm);
void reaper_destroy(struct reaper *reaper);
void reaper_add(struct reaper *reaper, pid_t pid);
typedef bool (*reaper_cb)(struct reaper *reaper, pid_t pid, void *data);
void reaper_add(struct reaper *reaper, pid_t pid, reaper_cb cb, void *cb_data);