6 * daemon-with-notify - turn a process into a daemon with parent exiting when
7 * child has decided that it has started correctly.
9 * Daemons should detach themselves thoroughly from the process which launched
10 * them, and not prevent any filesystems from being unmounted. daemonize()
11 * helps with the process.
13 * Daemon-with-notify is different in that the child can send a SIGUSR1 to
14 * the parent to indicate it has started (e.g. after memory allocation and
15 * other things that may fail) so that the parent can return a success or
16 * failing exit code and init scripts can pick this up easily.
19 * #include <ccan/daemon-with-notify/daemon.h>
20 * #include <ccan/str/str.h>
25 * static void usage(const char *name)
27 * errx(1, "Usage: %s [--daemonize]\n", name);
30 * // Wait for a minute, possibly as a daemon.
31 * int main(int argc, char *argv[])
34 * if (argc == 2 && streq(argv[1], "--daemonize")) {
35 * if (!daemonize(1, 1, 1))
36 * err(1, "Failed to become daemon");
40 * sleep(10); /* do some init here */
42 * sleep(20); /* will be done in child, detached from parent */
48 int main(int argc, char *argv[])
53 if (strcmp(argv[1], "depends") == 0) {
57 if (strcmp(argv[1], "libs") == 0) {