diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:49:52 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:49:52 +0000 |
commit | 55944e5e40b1be2afc4855d8d2baf4b73d1876b5 (patch) | |
tree | 33f869f55a1b149e9b7c2b7e201867ca5dd52992 /man/event-quick-child.c | |
parent | Initial commit. (diff) | |
download | systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.tar.xz systemd-55944e5e40b1be2afc4855d8d2baf4b73d1876b5.zip |
Adding upstream version 255.4.upstream/255.4
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | man/event-quick-child.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/man/event-quick-child.c b/man/event-quick-child.c new file mode 100644 index 0000000..8195efb --- /dev/null +++ b/man/event-quick-child.c @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: MIT-0 */ + +#include <assert.h> +#include <stdio.h> +#include <unistd.h> +#include <sd-event.h> + +int main(int argc, char **argv) { + pid_t pid = fork(); + assert(pid >= 0); + + /* SIGCHLD signal must be blocked for sd_event_add_child to work */ + sigset_t ss; + sigemptyset(&ss); + sigaddset(&ss, SIGCHLD); + sigprocmask(SIG_BLOCK, &ss, NULL); + + if (pid == 0) /* child */ + sleep(1); + + else { /* parent */ + sd_event *e = NULL; + int r; + + /* Create the default event loop */ + sd_event_default(&e); + assert(e); + + /* We create a floating child event source (attached to 'e'). + * The default handler will be called with 666 as userdata, which + * will become the exit value of the loop. */ + r = sd_event_add_child(e, NULL, pid, WEXITED, NULL, (void*) 666); + assert(r >= 0); + + r = sd_event_loop(e); + assert(r == 666); + + sd_event_unref(e); + } + + return 0; +} |