X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FDaemon%2FDaemon.hh;h=f0d3e6b50c8fc86b0ce2da51210fc54d0c3015c0;hb=532240d72e09e19e57fac9bb55c2560b9c9e5b97;hp=d0ba4a7cead310352f9c6598b0c46221cedb6ec1;hpb=d5ba3d7759212c90a5f4a25baf0dc38e290c3b64;p=senf.git diff --git a/Utils/Daemon/Daemon.hh b/Utils/Daemon/Daemon.hh index d0ba4a7..f0d3e6b 100644 --- a/Utils/Daemon/Daemon.hh +++ b/Utils/Daemon/Daemon.hh @@ -23,11 +23,12 @@ /** \file \brief Daemon public header */ -#ifndef HH_Daemon_ -#define HH_Daemon_ 1 +#ifndef HH_SENF_Utils_Daemon_Daemon_ +#define HH_SENF_Utils_Daemon_Daemon_ 1 // Custom includes #include +#include "../Logger/SenfLog.hh" //#include "Daemon.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -36,8 +37,7 @@ namespace senf { /** \brief %Daemon process - %senf::Daemon provides simple management for daemon processes. Specifically, the %Daemon class - implements + The %Daemon class provides simple management for daemon processes. Specifically, it implements \li Safe startup. If the startup fails, the foreground process which launches the daemon will terminate with an appropriate error exit code. \li Straight forward application initialization. The daemon process is forked before @@ -103,6 +103,8 @@ namespace senf { class Daemon : boost::noncopyable { public: + SENF_LOG_CLASS_AREA(); + /////////////////////////////////////////////////////////////////////////// // Types @@ -154,16 +156,23 @@ namespace senf { successful startup. */ int argc(); ///< Access command line parameter count - char ** argv(); ///< Access command line parameters + char const ** argv(); ///< Access command line parameters + void removeDaemonArgs(); ///< Remove the daemon arguments from argc()/argv() static void exit(unsigned code=0); ///< Terminate daemon with failure + void logReopen(); ///< Reopen the log files + /**< This is used when rotating the logs. By default, + SIGHUP calls logReopen. */ + ///\} - int start(int argc, char ** argv); ///< Called from main() to launch daemon. + int start(int argc, char const ** argv); ///< Called from main() to launch daemon. /**< Normally not called directly but from the \ref SENF_DAEMON_MAIN macro. */ + static Daemon & instance(); ///< Return the Daemon instance + protected: Daemon(); @@ -201,7 +210,7 @@ namespace senf { void installSighandlers(); int argc_; - char ** argv_; + char const ** argv_; bool daemonize_; std::string stdoutLog_; @@ -212,6 +221,8 @@ namespace senf { bool pidfileCreated_; bool detached_; + + static Daemon * instance_; }; /** \brief Provide \c main() function @@ -222,7 +233,7 @@ namespace senf { \ingroup process */ # define SENF_DAEMON_MAIN(klass) \ - int main(int argc, char ** argv) \ + int main(int argc, char const ** argv) \ { \ klass instance; \ return instance.start(argc, argv); \ @@ -231,7 +242,7 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// -//#include "Daemon.cci" +#include "Daemon.cci" //#include "Daemon.ct" //#include "Daemon.cti" #endif