/** \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 <boost/utility.hpp>
+#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 <i>Safe startup.</i> If the startup fails, the foreground process which launches the
daemon will terminate with an appropriate error exit code.
\li <i>Straight forward application initialization.</i> The daemon process is forked before
class Daemon : boost::noncopyable
{
public:
+ SENF_LOG_CLASS_AREA();
+
///////////////////////////////////////////////////////////////////////////
// Types
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
- 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. */
///\}
/**< Normally not called directly but from the
\ref SENF_DAEMON_MAIN macro. */
+ static Daemon & instance(); ///< Return the Daemon instance
+
protected:
Daemon();
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_;
int stdout_;
int stderr_;
std::string pidfile_;
+ bool pidfileCreated_;
bool detached_;
+
+ static Daemon * instance_;
};
/** \brief Provide \c main() function
}
///////////////////////////////hh.e////////////////////////////////////////
-//#include "Daemon.cci"
+#include "Daemon.cci"
//#include "Daemon.ct"
//#include "Daemon.cti"
#endif