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