From 78633439d9e5295640ee5f1e2c6294040227f84d Mon Sep 17 00:00:00 2001 From: Asela Fernando <25498128+aselafernando@users.noreply.github.com> Date: Mon, 5 Feb 2024 10:39:17 +1100 Subject: [PATCH] Added systemd watchdog & notify compatiblity The type of service for systemd can now be changed to Notify and a WatchdogSec can be set --- app/app.pro | 1 + app/main.cpp | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/app.pro b/app/app.pro index 7aa2606..c23e180 100644 --- a/app/app.pro +++ b/app/app.pro @@ -4,6 +4,7 @@ QT += gui widgets qml quick CONFIG += c++11 link_pkgconfig welleio QMAKE_CXXFLAGS += -Wno-unused-parameter INCLUDEPATH += $${PWD}/includes +LIBS += -lsystemd include("../config.pri") diff --git a/app/main.cpp b/app/main.cpp index 04fc322..e57e06f 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include "hudloader.h" @@ -40,7 +42,7 @@ int main(int argc, char *argv[]) parser.setApplicationDescription("viktorgino's HeadUnit Desktop"); parser.addHelpOption(); parser.addVersionOption(); - + QCommandLineOption pluginsOption(QStringList() << "p" << "plugins", QCoreApplication::translate("main", "Plugins to enable (defaults to all)"), QCoreApplication::translate("main", "plugins") @@ -68,6 +70,22 @@ int main(int argc, char *argv[]) qDebug("%lld ms : Loading theme loader", time.elapsed()); engine->load(QUrl(QStringLiteral("qrc:/loader.qml"))); + // If service Type=notify the service is only considered ready once we send this + sd_notify(0, "READY=1"); + + uint64_t watchdogIntervalUs = 0; + QTimer watchdogTimer; + QObject::connect(&watchdogTimer, &QTimer::timeout, [](){ + sd_notify(0, "WATCHDOG=1"); + }); + + // Service WatchdogSec must be set for this to return > 0 + if (sd_watchdog_enabled(0, &watchdogIntervalUs) > 0) { + qDebug("Systemd watchdog is enabled with %lu us\n", watchdogIntervalUs); + // Recommended reporting interval is half the watchdog interval + watchdogTimer.start(watchdogIntervalUs / 2000); + } + qDebug("%lld ms : Starting main loop", time.elapsed()); int ret = app.exec();