diff --git a/src/lib/utils/daemon.cpp b/src/lib/utils/daemon.cpp index 5aa7adcb..793dc1b2 100644 --- a/src/lib/utils/daemon.cpp +++ b/src/lib/utils/daemon.cpp @@ -81,7 +81,7 @@ void Daemon::run(const char* pidfile) close(STDERR_FILENO); // write pidfile and try to lock it - if (pidfile_open() == false) { + if (m_pidfile != NULL && pidfile_open() == false) { cerr << "can't open pidfile: %s" << m_pidfile << endl; exit(EXIT_FAILURE); } diff --git a/src/lib/utils/daemon.h b/src/lib/utils/daemon.h index 4d5e1ac8..bee00554 100644 --- a/src/lib/utils/daemon.h +++ b/src/lib/utils/daemon.h @@ -20,6 +20,8 @@ #ifndef LIBUTILS_DAEMON_H_ #define LIBUTILS_DAEMON_H_ +#include + /** \file daemon.h */ /** @@ -44,7 +46,7 @@ public: /** * @brief stop daemon and delete the pid file. */ - void stop() { pidfile_close(); } + void stop() { if (m_pidfile != NULL) pidfile_close(); } /** * @brief show actual status if daemonize. @@ -56,7 +58,7 @@ private: /** * @brief private construtor. */ - Daemon() {} + Daemon() : m_status(false), m_pidfile(NULL), m_pidfd(0) {} /** * @brief private copy construtor.