From 5c330e9d4f9b946063314ba6e8f4134fd20b5e3a Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Fri, 5 May 2023 11:15:34 +0200 Subject: [PATCH] Share "Last reload attempt failed" time across Icinga process tree on *nix ... as only the umbrella process knows that time, but the icinga check running in the main process also needs to know it. refs #8428 --- lib/base/application.cpp | 15 ++++++++++++++- lib/base/application.hpp | 8 ++++++++ lib/cli/daemoncommand.cpp | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 305107c9814..89a0f55a2e3 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -62,7 +62,12 @@ int Application::m_ArgC; char **Application::m_ArgV; double Application::m_StartTime; bool Application::m_ScriptDebuggerEnabled = false; -double Application::m_LastReloadFailed; + +#ifdef _WIN32 +double Application::m_LastReloadFailed = 0; +#else /* _WIN32 */ +SharedMemory Application::m_LastReloadFailed (0); +#endif /* _WIN32 */ #ifdef _WIN32 static LPTOP_LEVEL_EXCEPTION_FILTER l_DefaultUnhandledExceptionFilter = nullptr; @@ -1208,12 +1213,20 @@ void Application::SetScriptDebuggerEnabled(bool enabled) double Application::GetLastReloadFailed() { +#ifdef _WIN32 return m_LastReloadFailed; +#else /* _WIN32 */ + return m_LastReloadFailed.Get().load(); +#endif /* _WIN32 */ } void Application::SetLastReloadFailed(double ts) { +#ifdef _WIN32 m_LastReloadFailed = ts; +#else /* _WIN32 */ + m_LastReloadFailed.Get().store(ts); +#endif /* _WIN32 */ } void Application::ValidateName(const Lazy& lvalue, const ValidationUtils& utils) diff --git a/lib/base/application.hpp b/lib/base/application.hpp index 53d0b0c8b73..0578b8aa8bc 100644 --- a/lib/base/application.hpp +++ b/lib/base/application.hpp @@ -4,9 +4,11 @@ #define APPLICATION_H #include "base/i2-base.hpp" +#include "base/atomic.hpp" #include "base/application-ti.hpp" #include "base/logger.hpp" #include "base/configuration.hpp" +#include "base/shared-memory.hpp" #include namespace icinga @@ -137,7 +139,13 @@ class Application : public ObjectImpl { static double m_StartTime; static double m_MainTime; static bool m_ScriptDebuggerEnabled; +#ifdef _WIN32 static double m_LastReloadFailed; +#else /* _WIN32 */ + typedef Atomic AtomicTs; + static_assert(AtomicTs::is_always_lock_free); + static SharedMemory m_LastReloadFailed; +#endif /* _WIN32 */ #ifdef _WIN32 static BOOL WINAPI CtrlHandler(DWORD type); diff --git a/lib/cli/daemoncommand.cpp b/lib/cli/daemoncommand.cpp index 1fca07b5cc8..3a9ce8c0a74 100644 --- a/lib/cli/daemoncommand.cpp +++ b/lib/cli/daemoncommand.cpp @@ -813,6 +813,7 @@ int DaemonCommand::Run(const po::variables_map& vm, const std::vector