X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fdaemon_with_notify%2F_info;fp=ccan%2Fdaemon_with_notify%2F_info;h=6f26898e2a60326e73e79acdf3eb9759b1d9fb1f;hp=0000000000000000000000000000000000000000;hb=aaf830998ef2dc127dd09f30fc9a2156e0634a57;hpb=bd12721599802b1a91513ae56c0ab002890c60b0 diff --git a/ccan/daemon_with_notify/_info b/ccan/daemon_with_notify/_info new file mode 100644 index 00000000..6f26898e --- /dev/null +++ b/ccan/daemon_with_notify/_info @@ -0,0 +1,63 @@ +#include +#include +#include "config.h" + +/** + * daemon_with_notify - daemonize a process, can wait for child to signal readiness + * + * Daemons should detach themselves thoroughly from the process which launched + * them, and not prevent any filesystems from being unmounted. daemonize() + * helps with the process. + * + * Daemon-with-notify is different in that the child can send a SIGUSR1 to + * the parent to indicate it has started (e.g. after memory allocation and + * other things that may fail) so that the parent can return a success or + * failing exit code and init scripts can pick this up easily. + * + * Example: + * #include + * #include + * #include + * #include + * #include + * + * static void usage(const char *name) + * { + * errx(1, "Usage: %s [--daemonize]\n", name); + * } + * + * // Wait for a minute, possibly as a daemon. + * int main(int argc, char *argv[]) + * { + * if (argc != 1) { + * if (argc == 2 && streq(argv[1], "--daemonize")) { + * if (!daemonize(1, 1, 1)) + * err(1, "Failed to become daemon"); + * } else + * usage(argv[1]); + * } + * sleep(10); // do some init here + * daemon_is_ready(); + * sleep(20); // will be done in child, detached from parent + * exit(0); + * } + * + * License: BSD + * Author: Stewart Smith + */ +int main(int argc, char *argv[]) +{ + if (argc != 2) + return 1; + + if (strcmp(argv[1], "depends") == 0) { + return 0; + } + + if (strcmp(argv[1], "libs") == 0) { + return 0; + } + + return 1; +} +