1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

Added support for the systemd watchdog

This commit is contained in:
Klaus Schmidinger 2016-12-23 14:36:24 +01:00
parent bac0ca39ba
commit e2ba3d09a5
3 changed files with 34 additions and 1 deletions

View File

@ -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

View File

@ -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),

33
vdr.c
View File

@ -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();
}