X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FDaemon%2FDaemon.hh;h=89e2d53fe27273ae931c5102e93f0720d6ce56c5;hb=2c6294b3a810ee64e117df1b0da01d6b120534bb;hp=dc3fb2942a67d36c5eda906b03a4cb13d1aedadc;hpb=b41b8147c7a2d40e2f69471e183840be8a0b95da;p=senf.git diff --git a/Utils/Daemon/Daemon.hh b/Utils/Daemon/Daemon.hh index dc3fb29..89e2d53 100644 --- a/Utils/Daemon/Daemon.hh +++ b/Utils/Daemon/Daemon.hh @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer NETwork research (NET) +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -28,15 +28,16 @@ // Custom includes #include +#include "../Logger/SenfLog.hh" //#include "Daemon.mpp" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { - /** \brief Daemon process + /** \brief %Daemon process - senf::Daemon provides simple management for daemon processes. Specifically, the Daemon class + %senf::Daemon provides simple management for daemon processes. Specifically, the %Daemon class implements \li Safe startup. If the startup fails, the foreground process which launches the daemon will terminate with an appropriate error exit code. @@ -103,6 +104,8 @@ namespace senf { class Daemon : boost::noncopyable { public: + SENF_LOG_CLASS_AREA(); + /////////////////////////////////////////////////////////////////////////// // Types @@ -154,16 +157,23 @@ namespace senf { successful startup. */ int argc(); ///< Access command line parameter count - char const ** argv(); ///< Access command line parameters + char ** 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 fail(unsigned code=1); ///< 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 +205,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_; @@ -209,8 +219,11 @@ namespace senf { int stdout_; int stderr_; std::string pidfile_; + bool pidfileCreated_; bool detached_; + + static Daemon * instance_; }; /** \brief Provide \c main() function @@ -221,7 +234,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); \