From c917f87b00d8a0e8d2bd21f10417e5bad7a76f7d Mon Sep 17 00:00:00 2001 From: Timo Lotterbach Date: Tue, 20 Nov 2012 03:04:53 -0800 Subject: [PATCH] LayerManagerService: added systemd health monitor the systemd health monitor supports control of the systemd watchdog Signed-off-by: Timo Lotterbach --- LayerManagerService/CMakeLists.txt | 1 + LayerManagerService/include/HealthSystemd.h | 39 ++++++++++++++ LayerManagerService/src/HealthSystemd.cpp | 80 +++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 LayerManagerService/include/HealthSystemd.h create mode 100644 LayerManagerService/src/HealthSystemd.cpp diff --git a/LayerManagerService/CMakeLists.txt b/LayerManagerService/CMakeLists.txt index 20ba91e..d26c2d2 100644 --- a/LayerManagerService/CMakeLists.txt +++ b/LayerManagerService/CMakeLists.txt @@ -79,6 +79,7 @@ add_executable(LayerManagerService_Test src/GraphicalSurface.cpp src/Layermanager.cpp src/InputManager.cpp + src/HealthSystemd.cpp src/Scene.cpp src/shader/Shader.cpp src/shader/ShaderProgram.cpp diff --git a/LayerManagerService/include/HealthSystemd.h b/LayerManagerService/include/HealthSystemd.h new file mode 100644 index 0000000..f227cf1 --- /dev/null +++ b/LayerManagerService/include/HealthSystemd.h @@ -0,0 +1,39 @@ +/*************************************************************************** +* +* Copyright 2012 BMW Car IT GmbH +* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +****************************************************************************/ + +#ifndef __HEALTHSYSTEMD_H__ +#define __HEALTHSYSTEMD_H__ + +#include "IHealth.h" + +class HealthSystemd : public IHealth +{ +public: + HealthSystemd(); + virtual void reportStartupComplete(); + virtual void reportProcessId(); + virtual int getWatchdogIntervalInMs(); + virtual void signalWatchdog(); + virtual bool watchdogEnabled(); + +private: + int mIntervalInMs; +}; + +#endif // __HEALTHSYSTEMD_H__ \ No newline at end of file diff --git a/LayerManagerService/src/HealthSystemd.cpp b/LayerManagerService/src/HealthSystemd.cpp new file mode 100644 index 0000000..b393e40 --- /dev/null +++ b/LayerManagerService/src/HealthSystemd.cpp @@ -0,0 +1,80 @@ +/*************************************************************************** +* +* Copyright 2012 BMW Car IT GmbH +* +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* +****************************************************************************/ +#include "HealthSystemd.h" +#include "config.h" +#include "Log.h" +#include +#include + +#ifdef WITH_SYSTEMD + #include +#else + #define sd_notify(a,b) + #define sd_notifyf(a,b,c) +#endif + + +HealthSystemd::HealthSystemd() +: mIntervalInMs(-1) +{ + char* envVar = getenv("WATCHDOG_USEC"); + if (envVar) + { + // to ms, watchdog should trigger twice the frequency + mIntervalInMs = atoi(envVar) / 2000; + LOG_INFO("HealthSystemd", "Watchdog interval is " << mIntervalInMs << "ms"); + } + else + { + LOG_INFO("HealthSystemd", "Watchdog interval not defined, watchdog disabled"); + } +} + +void HealthSystemd::reportStartupComplete() +{ + LOG_INFO("HealthSystemd", "reporting startup complete"); + sd_notify(0, "READY=1"); +} + +void HealthSystemd::reportProcessId() +{ + if (watchdogEnabled()) + { + sd_notifyf(0, "MAINPID=%d", getpid()); + } +} + +int HealthSystemd::getWatchdogIntervalInMs() +{ + return mIntervalInMs; +} + +void HealthSystemd::signalWatchdog() +{ + if (watchdogEnabled()) + { + LOG_DEBUG("HealthSystemd", "Watchdog fired"); + sd_notify(0, "WATCHDOG=1"); + } +} + +bool HealthSystemd::watchdogEnabled() +{ + return (mIntervalInMs > 0); +} -- 2.7.4