_info 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "config.h"
  4. /**
  5. * daemon_with_notify - daemonize a process, can wait for child to signal readiness
  6. *
  7. * Daemons should detach themselves thoroughly from the process which launched
  8. * them, and not prevent any filesystems from being unmounted. daemonize()
  9. * helps with the process.
  10. *
  11. * Daemon-with-notify is different in that the child can send a SIGUSR1 to
  12. * the parent to indicate it has started (e.g. after memory allocation and
  13. * other things that may fail) so that the parent can return a success or
  14. * failing exit code and init scripts can pick this up easily.
  15. *
  16. * Example:
  17. * #include <ccan/daemon_with_notify/daemon_with_notify.h>
  18. * #include <ccan/str/str.h>
  19. * #include <err.h>
  20. * #include <unistd.h>
  21. * #include <stdlib.h>
  22. *
  23. * static void usage(const char *name)
  24. * {
  25. * errx(1, "Usage: %s [--daemonize]\n", name);
  26. * }
  27. *
  28. * // Wait for a minute, possibly as a daemon.
  29. * int main(int argc, char *argv[])
  30. * {
  31. * if (argc != 1) {
  32. * if (argc == 2 && streq(argv[1], "--daemonize")) {
  33. * if (!daemonize(1, 1, 1))
  34. * err(1, "Failed to become daemon");
  35. * } else
  36. * usage(argv[1]);
  37. * }
  38. * sleep(10); // do some init here
  39. * daemon_is_ready();
  40. * sleep(20); // will be done in child, detached from parent
  41. * exit(0);
  42. * }
  43. *
  44. * License: BSD (3 clause)
  45. * Author: Stewart Smith <stewart@flamingspork.com>
  46. */
  47. int main(int argc, char *argv[])
  48. {
  49. if (argc != 2)
  50. return 1;
  51. if (strcmp(argv[1], "depends") == 0) {
  52. return 0;
  53. }
  54. if (strcmp(argv[1], "libs") == 0) {
  55. return 0;
  56. }
  57. return 1;
  58. }