Use -O not -O3: reduces ccan/tdb test time from 24 to 18 seconds.
[ccan] / ccan / daemonize / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * daemonize - routine to turn a process into a well-behaved daemon.
7  *
8  * Daemons should detach themselves thoroughly from the process which launched
9  * them, and not prevent any filesystems from being unmounted.  daemonize()
10  * helps with the process.
11  *
12  * Example:
13  *      #include <ccan/daemonize/daemonize.h>
14  *      #include <ccan/str/str.h>
15  *      #include <err.h>
16  *      #include <unistd.h>
17  *      #include <stdlib.h>
18  *      
19  *      static void usage(const char *name)
20  *      {
21  *              errx(1, "Usage: %s [--daemonize]\n", name);
22  *      }
23  *      
24  *      // Wait for a minute, possibly as a daemon.
25  *      int main(int argc, char *argv[])
26  *      {
27  *              if (argc != 1) {
28  *                      if (argc == 2 && streq(argv[1], "--daemonize")) {
29  *                              if (!daemonize())
30  *                                      err(1, "Failed to become daemon");
31  *                      } else
32  *                              usage(argv[1]);
33  *              }
34  *              sleep(60);
35  *              exit(0);
36  *      }
37  *
38  * Licence: BSD (2 clause, ie. MIT)
39  */
40 int main(int argc, char *argv[])
41 {
42         if (argc != 2)
43                 return 1;
44
45         if (strcmp(argv[1], "depends") == 0) {
46                 return 0;
47         }
48
49         if (strcmp(argv[1], "libs") == 0) {
50                 return 0;
51         }
52
53         return 1;
54 }