X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FDaemon%2FDaemon.hh;h=f0d3e6b50c8fc86b0ce2da51210fc54d0c3015c0;hb=bd9f9d3fd6fbcff0112a7bf48ab9284da9576b11;hp=3fb0018a3e45771ff229233071ff6d2e56052a75;hpb=d267cc9325ff49f1ef76aa7ddf6b51ceaafd3026;p=senf.git diff --git a/Utils/Daemon/Daemon.hh b/Utils/Daemon/Daemon.hh index 3fb0018..f0d3e6b 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 @@ -23,21 +23,21 @@ /** \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//////////////////////////////////////// namespace senf { - /** \brief Daemon process + /** \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 @@ -155,8 +157,13 @@ namespace senf { int argc(); ///< Access command line parameter count 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 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. */ ///\} @@ -164,6 +171,8 @@ namespace senf { /**< Normally not called directly but from the \ref SENF_DAEMON_MAIN macro. */ + static Daemon & instance(); ///< Return the Daemon instance + protected: Daemon(); @@ -195,10 +204,10 @@ 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_; @@ -209,8 +218,11 @@ namespace senf { int stdout_; int stderr_; std::string pidfile_; + bool pidfileCreated_; bool detached_; + + static Daemon * instance_; }; /** \brief Provide \c main() function @@ -230,7 +242,7 @@ namespace senf { } ///////////////////////////////hh.e//////////////////////////////////////// -//#include "Daemon.cci" +#include "Daemon.cci" //#include "Daemon.ct" //#include "Daemon.cti" #endif