1 /* Licensed under BSD-MIT - see LICENSE file for details */
2 #include <ccan/daemonize/daemonize.h>
9 /* This code is based on Stevens Advanced Programming in the UNIX
15 /* Separate from our parent via fork, so init inherits us. */
16 if ((pid = fork()) < 0)
21 /* Don't hold files open. */
26 /* Many routines write to stderr; that can cause chaos if used
27 * for something else, so set it here. */
28 if (open("/dev/null", O_WRONLY) != 0)
30 if (dup2(0, STDERR_FILENO) != STDERR_FILENO)
34 /* Session leader so ^C doesn't whack us. */
36 /* Move off any mount points we might be in. */
40 /* Discard our parent's old-fashioned umask prejudices. */