From c7df2496065f71bd427cdc646b3dbb8990a394f4 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 17 Jul 2012 16:06:31 +0200 Subject: [PATCH] Daemon: More documentation --- ucw/doc/daemon.txt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ucw/doc/daemon.txt b/ucw/doc/daemon.txt index a5a23dc4..10062100 100644 --- a/ucw/doc/daemon.txt +++ b/ucw/doc/daemon.txt @@ -1,6 +1,20 @@ Daemonization helper ==================== -FIXME: Add general description +When programs run as daemons, they frequently forget to detach themselves +from the parent environment. LibUCW therefore offers a simple daemonization +helper which performs the necessary actions. Namely: + +* Establishing a new session via a call to `setsid()`. +* Switching the user and group ID if needed. The user and group can be specified + by either a name or `#uid`. If only the user is given, the relevant groups are + set according to `/etc/passwd` and `/etc/group`. +* Redirecting standard input and output from `/dev/null`. Standard error + output is left open, so that error messages can be printed before you + set up proper <>. +* Setting the `umask()` to a fixed value (022). +* Switching from the current directory to `/`, so that it is not kept busy. +* Writing a PID file. While the daemon is running, the PID file is kept locked + by `flock()`, so we can easily detect stale PID files. !!ucw/daemon.h -- 2.39.5