15e4e7d812dad7b393bde9837b36cf9412805649
[senf.git] / Utils / DaemonTools.hh
1 // $Id$
2 //
3 // Copyright (C) 2006 Stefan Bund <g0dil@senf.berlios.de>
4 //
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.
9 //
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.
14 //
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.
19
20 /** \file
21     \brief DaemonTools public header */
22
23 /** \defgroup process Process Management
24
25     This collection of utilities provides help in managing daemon processes.
26
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).
32
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.
37
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.
41
42     \idea We might want to add other oft used utitlities: chroot(), setreuid(), pipes() / IPC ...
43  */
44
45 #ifndef HH_DaemonTools_
46 #define HH_DaemonTools_ 1
47
48 // Custom includes
49 #include <string>
50
51 //#include "DaemonTools.mpp"
52 ///////////////////////////////hh.p////////////////////////////////////////
53
54 namespace senf {
55
56     /// \addtogroup process
57     /// @{
58
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 */
66
67     /// @}
68 }
69
70 ///////////////////////////////hh.e////////////////////////////////////////
71 //#include "DaemonTools.cci"
72 //#include "DaemonTools.ct"
73 //#include "DaemonTools.cti"
74 //#include "DaemonTools.mpp"
75 #endif
76
77 \f
78 // Local Variables:
79 // mode: c++
80 // fill-column: 100
81 // c-file-style: "senf"
82 // indent-tabs-mode: nil
83 // ispell-local-dictionary: "american"
84 // compile-command: "scons -u test"
85 // comment-column: 40
86 // End: