3 // Copyright (C) 2006 Stefan Bund <g0dil@senf.berlios.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the
17 // Free Software Foundation, Inc.,
18 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 \brief DaemonTools public header */
23 /** \defgroup process Process Management
25 This collection of utilities provides help in managing daemon processes.
27 \idea Add communication between parent and child process to daemonize() and add things like
28 init_done(), failure() etc which allow the daemon process to tell the frontend of successful
29 startup or failure. This probably means moving all the methods into a DaemonTools class (as
30 statics or via a singleton). This would also allow for automatic pid file creation and
31 removal (remove in global destructor).
33 \idea Add a DaemonProcess baseclass with init() and main() abstract members which wraps the
34 startup process. DaeminProcess::run() would fork, call init(), create a pid file and then
35 call main(). Exceptions during init()'s execution would be passed to the parent
36 process. This is based on the above API.
38 \idea A closeall()/closemost() function which is useful when starting child processes. We'll use
39 getrlimit to now the biggest filehandle and close all of em. closemost() takes a number of
40 file handles as arg and will keep those open.
42 \idea We might want to add other oft used utitlities: chroot(), setreuid(), pipes() / IPC ...
45 #ifndef HH_DaemonTools_
46 #define HH_DaemonTools_ 1
51 //#include "DaemonTools.mpp"
52 ///////////////////////////////hh.p////////////////////////////////////////
56 /// \addtogroup process
59 void daemonize(); ///< Make the current process a daemon process
60 /**< daemonize() will fork, detach from the controlling
61 terminal and start a new process group. */
62 void redirect_stdio(std::string const & path = "/dev/null"); ///< Redirect STDIN, STDOUT and STDERR
63 /**< All standard file-descriptors will be redirected to the
64 given path defaulting to <tt>/dev/null</tt>
65 \param[in] path path to redirect to */
70 ///////////////////////////////hh.e////////////////////////////////////////
71 //#include "DaemonTools.cci"
72 //#include "DaemonTools.ct"
73 //#include "DaemonTools.cti"
74 //#include "DaemonTools.mpp"
81 // c-file-style: "senf"
82 // indent-tabs-mode: nil
83 // ispell-local-dictionary: "american"
84 // compile-command: "scons -u test"