1 /* SPDX-License-Identifier: CC0-1.0 */
2
3 #include <assert.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <sd-event.h>
7
main(int argc,char ** argv)8 int main(int argc, char **argv) {
9 pid_t pid = fork();
10 assert(pid >= 0);
11
12 /* SIGCHLD signal must be blocked for sd_event_add_child to work */
13 sigset_t ss;
14 sigemptyset(&ss);
15 sigaddset(&ss, SIGCHLD);
16 sigprocmask(SIG_BLOCK, &ss, NULL);
17
18 if (pid == 0) /* child */
19 sleep(1);
20
21 else { /* parent */
22 sd_event *e = NULL;
23 int r;
24
25 /* Create the default event loop */
26 sd_event_default(&e);
27 assert(e);
28
29 /* We create a floating child event source (attached to 'e').
30 * The default handler will be called with 666 as userdata, which
31 * will become the exit value of the loop. */
32 r = sd_event_add_child(e, NULL, pid, WEXITED, NULL, (void*) 666);
33 assert(r >= 0);
34
35 r = sd_event_loop(e);
36 assert(r == 666);
37
38 sd_event_unref(e);
39 }
40
41 return 0;
42 }
43