]> granicus.if.org Git - icinga2/commitdiff
Fix crash in the unit tests
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 12 Nov 2014 08:33:13 +0000 (09:33 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 12 Nov 2014 08:33:13 +0000 (09:33 +0100)
fixes #7648

icinga-app/icinga.cpp
lib/base/application.cpp
lib/base/application.hpp
lib/base/timer.cpp
test/base-timer.cpp
test/test.cpp

index b59ff4fd723b6f7f56f82bdf3a97a6726b034f08..e05ee9cf7e583abd5bbc164bdea480119185feaa 100644 (file)
@@ -422,10 +422,6 @@ int Main(void)
                rc = command->Run(vm, args);
        }
 
-#ifndef _DEBUG
-       Application::Exit(rc);
-#endif /* _DEBUG */
-
        return rc;
 }
 
@@ -581,6 +577,8 @@ VOID WINAPI ServiceMain(DWORD argc, LPSTR *argv)
        int rc = Main();
 
        ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, rc);
+
+       Application::Exit(rc);
 }
 #endif /* _WIN32 */
 
index 27be627919abc443085fb8175677fb1d4a31e47f..fe6512185fd45cadc70b11386730ace2cecdeca3 100644 (file)
@@ -109,11 +109,19 @@ void Application::Exit(int rc)
                logger->Flush();
        }
 
+       UninitializeBase();
+
+#ifdef _DEBUG
+       exit(rc);
+#else /* _DEBUG */
        _exit(rc); // Yay, our static destructors are pretty much beyond repair at this point.
+#endif /* _DEBUG */
 }
 
 void Application::InitializeBase(void)
 {
+       Timer::Initialize();
+
 #ifndef _WIN32
        rlimit rl;
        if (getrlimit(RLIMIT_NOFILE, &rl) >= 0) {
@@ -146,6 +154,11 @@ void Application::InitializeBase(void)
        Utility::ExecuteDeferredInitializers();
 }
 
+void Application::UninitializeBase(void)
+{
+       Timer::Uninitialize();
+}
+
 /**
  * Retrieves a pointer to the application singleton object.
  *
index 42db856965357a99eec20906f0331d518f542f45..862237a72c7a4de75e93b8852b19cb5548505a98 100644 (file)
@@ -43,6 +43,7 @@ public:
        ~Application(void);
 
        static void InitializeBase(void);
+       static void UninitializeBase(void);
 
        static Application::Ptr GetInstance(void);
 
index 7538a16b307ec991b184edbf7c47207ff1382720..d07774c146215bd5461b4e7528bab94d5cdd1908 100644 (file)
@@ -150,6 +150,9 @@ void Timer::Stop(void)
 {
        ASSERT(!OwnsLock());
 
+       if (l_StopThread)
+               return;
+
        boost::mutex::scoped_lock lock(l_Mutex);
 
        m_Started = false;
index 115d9542a3ac8d9c3f727420e0274ec662ecd01c..713597ecce2bb9bb092b79eb321d2280a91d885e 100644 (file)
 
 using namespace icinga;
 
-struct TimerFixture
-{
-       TimerFixture(void)
-       {
-               Timer::Initialize();
-       }
-
-       ~TimerFixture(void)
-       {
-               Timer::Uninitialize();
-       }
-};
-
-BOOST_FIXTURE_TEST_SUITE(base_timer, TimerFixture)
+BOOST_AUTO_TEST_SUITE(base_timer)
 
 BOOST_AUTO_TEST_CASE(construct)
 {
index af024d66ef06470396d3283f1efa0f58febb91fd..4076eae7ef6831f5f93ce904421b6a151588396d 100644 (file)
@@ -31,6 +31,11 @@ struct InitLibBase
        {
                Application::InitializeBase();
        }
+
+       ~InitLibBase(void)
+       {
+               Application::UninitializeBase();
+       }
 };
 
 BOOST_GLOBAL_FIXTURE(InitLibBase);