Hi,

Here is a patch I use to enable systemd watchdog support in VDR. It
doesn't replace the internal watchdog, it just allow setting
WatchdogSec directive in service file so if VDR watchdog is unable to
exit, systemd take care of restarting it.

I use this patch against VDR 2.2.0 without problem for few mouths (I
set systemd watchdog to the same value than VDR watchdog to avoid
interference between them). If you are interested to include it, I can
see if it apply to dev branch, but there is only ~20 lines so it should
apply without modification.

Note that the first and last chunk are only systemd notifications about
the current state of VDR and they can be removed if needed.

Regards,

Marc.

diff -Naur a/vdr.c b/vdr.c
--- a/vdr.c	2015-02-10 15:13:12.000000000 +0100
+++ b/vdr.c	2016-05-02 13:37:43.180638765 +0200
@@ -170,6 +170,9 @@
   // 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);
 }
 
@@ -234,6 +237,10 @@
 #if defined(VDR_USER)
   VdrUser = VDR_USER;
 #endif
+#ifdef SDNOTIFY
+  time_t SdWatchdog;
+  int SdWatchdogTimeout = 0;
+#endif
 
   cArgs *Args = NULL;
   if (argc == 1) {
@@ -904,6 +911,16 @@
      }
 
 #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
 
@@ -958,6 +975,14 @@
               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:
         if (!Channels.BeingEdited() && !Timers.BeingEdited()) {
            int modified = Channels.Modified();
@@ -1494,5 +1519,11 @@
      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();
 }
_______________________________________________
vdr mailing list
vdr@linuxtv.org
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr

Reply via email to