From 3ece2ba6435c6d0d7c73c586e0d40367b42dd079 Mon Sep 17 00:00:00 2001 From: Gerd von Egidy Date: Sun, 27 Apr 2014 23:40:37 +0200 Subject: [PATCH] Fix logging during shutdown procedure. Refs #5788 --- icinga-app/icinga.cpp | 5 ++--- lib/base/streamlogger.cpp | 9 +++++++++ lib/base/streamlogger.h | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 4eb7779fb..4208bed6a 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -200,10 +200,9 @@ static void TerminateAndWaitForEnd(pid_t target) int ret = kill(target, SIGTERM); - while(Utility::GetTime() < timeout && (ret==0 || errno!=ESRCH)) - { + while (Utility::GetTime() < timeout && (ret == 0 || errno != ESRCH)) { Utility::Sleep(0.1); - ret = kill(target, SIGTERM); + ret = kill(target, 0); } // timeout and the process still seems to live: kill it diff --git a/lib/base/streamlogger.cpp b/lib/base/streamlogger.cpp index fc457034d..6a3b11669 100644 --- a/lib/base/streamlogger.cpp +++ b/lib/base/streamlogger.cpp @@ -42,6 +42,15 @@ void StreamLogger::Start(void) m_Tty = false; } +void StreamLogger::Stop(void) +{ + Logger::Stop(); + + // make sure we flush the log data on shutdown, even if we don't call the destructor + if (m_Stream) + m_Stream->flush(); +} + /** * Destructor for the StreamLogger class. */ diff --git a/lib/base/streamlogger.h b/lib/base/streamlogger.h index 07fedf092..1d7246009 100644 --- a/lib/base/streamlogger.h +++ b/lib/base/streamlogger.h @@ -39,6 +39,7 @@ public: DECLARE_PTR_TYPEDEFS(StreamLogger); virtual void Start(void); + virtual void Stop(void); ~StreamLogger(void); void BindStream(std::ostream *stream, bool ownsStream);