]> mj.ucw.cz Git - libucw.git/blob - ucw/doc/daemon.txt
100621005f554bfc81e6d68fe47d5806cfabd6d8
[libucw.git] / ucw / doc / daemon.txt
1 Daemonization helper
2 ====================
3
4 When programs run as daemons, they frequently forget to detach themselves
5 from the parent environment. LibUCW therefore offers a simple daemonization
6 helper which performs the necessary actions. Namely:
7
8 * Establishing a new session via a call to `setsid()`.
9 * Switching the user and group ID if needed. The user and group can be specified
10   by either a name or `#uid`. If only the user is given, the relevant groups are
11   set according to `/etc/passwd` and `/etc/group`.
12 * Redirecting standard input and output from `/dev/null`. Standard error
13   output is left open, so that error messages can be printed before you
14   set up proper <<log:,logging>>.
15 * Setting the `umask()` to a fixed value (022).
16 * Switching from the current directory to `/`, so that it is not kept busy.
17 * Writing a PID file. While the daemon is running, the PID file is kept locked
18   by `flock()`, so we can easily detect stale PID files.
19
20 !!ucw/daemon.h