summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CONTRIBUTORS1
-rw-r--r--HISTORY1
-rw-r--r--vdr.c33
3 files changed, 34 insertions, 1 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index a25051e7..9b5448e1 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -3233,6 +3233,7 @@ Malte Forkel <malte.forkel@berlin.de>
Marc Perrudin <vdr@ekass.net>
for translating OSD texts to the French language
+ for adding support for the systemd watchdog
Bernard Jaulin <bernard.jaulin@gmail.com>
for translating OSD texts to the French language
diff --git a/HISTORY b/HISTORY
index 9cb96b8b..93fa8989 100644
--- a/HISTORY
+++ b/HISTORY
@@ -8878,3 +8878,4 @@ Video Disk Recorder Revision History
Lars Hanisch).
- Avoiding some duplicate code and unnecessary work in nit.c (thanks to Ville
Skyttä).
+- Added support for the systemd watchdog (thanks to Marc Perrudin),
diff --git a/vdr.c b/vdr.c
index 16a6c326..8a494714 100644
--- a/vdr.c
+++ b/vdr.c
@@ -22,7 +22,7 @@
*
* The project's page is at http://www.tvdr.de
*
- * $Id: vdr.c 4.8 2016/12/13 13:13:10 kls Exp $
+ * $Id: vdr.c 4.9 2016/12/23 14:34:37 kls Exp $
*/
#include <getopt.h>
@@ -171,6 +171,9 @@ static void Watchdog(int signum)
// Something terrible must have happened that prevented the 'alarm()' from
// being called in time, so let's get out of here:
esyslog("PANIC: watchdog timer expired - exiting!");
+#ifdef SDNOTIFY
+ sd_notify(0, "STOPPING=1\nSTATUS=PANIC");
+#endif
exit(1);
}
@@ -235,6 +238,10 @@ int main(int argc, char *argv[])
#if defined(VDR_USER)
VdrUser = VDR_USER;
#endif
+#ifdef SDNOTIFY
+ time_t SdWatchdog;
+ int SdWatchdogTimeout = 0;
+#endif
cArgs *Args = NULL;
if (argc == 1) {
@@ -914,6 +921,16 @@ int main(int argc, char *argv[])
}
#ifdef SDNOTIFY
+ if (sd_watchdog_enabled(0, NULL) > 0) {
+ uint64_t timeout;
+ SdWatchdog = time(NULL);
+ sd_watchdog_enabled(0, &timeout);
+ SdWatchdogTimeout = (int)timeout/1000000;
+ dsyslog("SD_WATCHDOG enabled with timeout set to %d seconds", SdWatchdogTimeout);
+ }
+
+ // Startup notification:
+
sd_notify(0, "READY=1\nSTATUS=Ready");
#endif
@@ -976,6 +993,14 @@ int main(int argc, char *argv[])
dsyslog("max. latency time %d seconds", MaxLatencyTime);
}
}
+#ifdef SDNOTIFY
+ // Ping systemd watchdog when half the timeout is elapsed:
+ if (SdWatchdogTimeout && (Now - SdWatchdog) * 2 > SdWatchdogTimeout) {
+ sd_notify(0, "WATCHDOG=1");
+ SdWatchdog = Now;
+ dsyslog("SD_WATCHDOG ping");
+ }
+#endif
// Handle channel and timer modifications:
{
// Channels and timers need to be stored in a consistent manner,
@@ -1565,5 +1590,11 @@ Exit:
closelog();
if (HasStdin)
tcsetattr(STDIN_FILENO, TCSANOW, &savedTm);
+#ifdef SDNOTIFY
+ if (ShutdownHandler.GetExitCode() == 2)
+ sd_notify(0, "STOPPING=1\nSTATUS=Startup failed, exiting");
+ else
+ sd_notify(0, "STOPPING=1\nSTATUS=Exiting");
+#endif
return ShutdownHandler.GetExitCode();
}