diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2016-12-23 14:36:24 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2016-12-23 14:36:24 +0100 |
commit | e2ba3d09a5239a9da9b1344a8bd671b85b0f987b (patch) | |
tree | fa1a4bcdb7cc30f98c7b1679e705c0e7793f72de /vdr.c | |
parent | bac0ca39babafb53f3aa8084f885937daf5f15d4 (diff) | |
download | vdr-e2ba3d09a5239a9da9b1344a8bd671b85b0f987b.tar.gz vdr-e2ba3d09a5239a9da9b1344a8bd671b85b0f987b.tar.bz2 |
Added support for the systemd watchdog
Diffstat (limited to 'vdr.c')
-rw-r--r-- | vdr.c | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -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(); } |