Daemon process management

The Daemon class provides the infrastructure to implement robust daemon processes. A daemon process is implemented by deriving from senf::Daemon and implementing the necessary (virtual) member functions.

class MyDaemon : public senf::Daemon
void configure() {
// Set configuration parameters like daemonize(), pidFile() etc
// The default version provided by senf::Daemon will parse some special command line
// parameters to configure the daemon manager. You may optionally call this version
// here after setting default parameters
void init() {
// Initialize application. Setup all necessary objects. After init()
// has completed, the startup should not fail
void run() {
// Main application code should be called here.
// Provide main() function
The startup procedure is divided into three steps:
\li First, configure() is called. configure() should be as simple as possible. It just needs to
    set the daemon parameters. No further setup should be done here.
\li init() is called after fork() but while still connected to the terminal. init() should do
    all necessary application setup. Here, all configuration or user errors should be detected
    and properly diagnosed.
\li After init() returns, the application will detach from the terminal. Now run() is called to
    enter the application main loop.

Since there are times, where separating init() and run() into two separate functions is
difficult, instead of defining init() and run(), the member main() may be defined. This member
must call detach() as soon as initialization is completed to detach from the foreground
class MyDaemon : public senf::Daemon
// 'configure()' like above. Don't implement 'init()' or 'run()' if you implement 'main()'.
void main() {
// Initialize application. Setup all necessary objects. When implementing main(), the
// objects will most often live on the stack.
MyAppObject app;
if (some_error)
// Call Daemon::exit() to terminate execution prematurely
// After initialization is complete, you *must* call 'detach()'.
// Now we can start the application main loop
// Provide main() function
    \ref senf::Daemon class \n
    \ref SENF_DAEMON_MAIN() main() implementation macro