From d078044c36b1b6ace4bc028167fb968eed2e5b98 Mon Sep 17 00:00:00 2001 From: john30 Date: Thu, 18 Dec 2014 22:04:23 +0100 Subject: [PATCH] initialize fields, allow missing pidfile --- src/lib/utils/daemon.cpp | 2 +- src/lib/utils/daemon.h | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) 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.