From f592a13481ec42fb555474d1f1e231f8ed9b5b67 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 12 Nov 2014 21:27:36 +0100 Subject: [PATCH] Make sure all threads are dead before calling fork() fixes #7653 --- lib/base/application.cpp | 9 +-------- lib/base/application.hpp | 1 - lib/base/timer.cpp | 3 ++- test/test.cpp | 4 +++- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 786cda166..204ca752d 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -109,7 +109,7 @@ void Application::Exit(int rc) logger->Flush(); } - UninitializeBase(); + Timer::Uninitialize(); #ifdef _DEBUG exit(rc); @@ -120,8 +120,6 @@ void Application::Exit(int rc) void Application::InitializeBase(void) { - Timer::Initialize(); - #ifndef _WIN32 rlimit rl; if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) { @@ -154,11 +152,6 @@ void Application::InitializeBase(void) Utility::ExecuteDeferredInitializers(); } -void Application::UninitializeBase(void) -{ - Timer::Uninitialize(); -} - /** * Retrieves a pointer to the application singleton object. * diff --git a/lib/base/application.hpp b/lib/base/application.hpp index 862237a72..42db85696 100644 --- a/lib/base/application.hpp +++ b/lib/base/application.hpp @@ -43,7 +43,6 @@ public: ~Application(void); static void InitializeBase(void); - static void UninitializeBase(void); static Application::Ptr GetInstance(void); diff --git a/lib/base/timer.cpp b/lib/base/timer.cpp index d07774c14..c16e41b02 100644 --- a/lib/base/timer.cpp +++ b/lib/base/timer.cpp @@ -81,7 +81,8 @@ void Timer::Uninitialize(void) l_CV.notify_all(); } - l_Thread.join(); + if (l_Thread.joinable()) + l_Thread.join(); } /** diff --git a/test/test.cpp b/test/test.cpp index 4076eae7e..d4fc3d279 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -21,6 +21,7 @@ #define BOOST_TEST_MODULE icinga2_test #include "base/application.hpp" +#include "base/timer.hpp" #include using namespace icinga; @@ -30,11 +31,12 @@ struct InitLibBase InitLibBase(void) { Application::InitializeBase(); + Timer::Initialize(); } ~InitLibBase(void) { - Application::UninitializeBase(); + Timer::Uninitialize(); } };