X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FDaemon%2FDaemon.hh;h=76e10e732186158778c6bf073df67a73055b6b9c;hb=b7f7003f523fa8251ac44b969374c7385d053cc4;hp=2a0ee697b167e16292c6297096669d4517b6f58e;hpb=d2459b6c8249291588fd3d0d125ed3d38e003b55;p=senf.git diff --git a/Utils/Daemon/Daemon.hh b/Utils/Daemon/Daemon.hh index 2a0ee69..76e10e7 100644 --- a/Utils/Daemon/Daemon.hh +++ b/Utils/Daemon/Daemon.hh @@ -28,6 +28,7 @@ // Custom includes #include +#include "../Logger/SenfLog.hh" //#include "Daemon.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -103,6 +104,8 @@ namespace senf { class Daemon : boost::noncopyable { public: + SENF_LOG_CLASS_AREA(); + /////////////////////////////////////////////////////////////////////////// // Types @@ -154,16 +157,22 @@ namespace senf { successful startup. */ int argc(); ///< Access command line parameter count - char const ** argv(); ///< Access command line parameters + char ** argv(); ///< Access command line parameters + + static void exit(unsigned code=0); ///< Terminate daemon with failure - 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 const ** argv); ///< Called from main() to launch daemon. + int start(int argc, char ** 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(); @@ -195,13 +204,13 @@ namespace senf { This member is only called, if the default main() implementation is not overridden. */ private: - void openLog(); void fork(); bool pidfileCreate(); + void installSighandlers(); int argc_; - char const ** argv_; + char ** 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 const ** argv) \ + int main(int argc, char ** argv) \ { \ klass instance; \ return instance.start(argc, argv); \