Signed-off-by: Victor Westerhuis <vic...@westerhu.is> --- debuginfod/debuginfod.cxx | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx index 35b5fc18..b31c77d3 100644 --- a/debuginfod/debuginfod.cxx +++ b/debuginfod/debuginfod.cxx @@ -94,6 +94,7 @@ using namespace std; #include <microhttpd.h> #ifdef ENABLE_SYSTEMD +#include <time.h> #include <systemd/sd-daemon.h> #endif @@ -3600,13 +3601,43 @@ main (int argc, char *argv[]) } } +#ifdef ENABLE_SYSTEMD + uint64_t timeout_usec; + int watchdog_enabled = sd_watchdog_enabled (true, &timeout_usec); + if (watchdog_enabled < 0) + report_error (0, -watchdog_enabled, + "warning: cannot determine if watchdog is enabled"); +#endif + /* Trivial main loop! */ #ifdef ENABLE_SYSTEMD (void) sd_notify (false, "READY=1"); #endif set_metric("ready", 1); - while (! interrupted) - pause (); +#ifdef ENABLE_SYSTEMD + if (watchdog_enabled > 0) + { + timeout_usec /= 2; + struct timespec timeout; + timeout.tv_sec = timeout_usec / 1000000; + timeout.tv_nsec = timeout_usec % 1000000 * 1000; + + rc = 0; + struct timespec remaining_timeout; + while (! interrupted) + { + if (rc == 0) + { + (void) sd_notify (false, "WATCHDOG=1"); + remaining_timeout = timeout; + } + rc = nanosleep (&remaining_timeout, &remaining_timeout); + } + } + else +#endif + while (! interrupted) + pause (); scanq.nuke(); // wake up any remaining scanq-related threads, let them die set_metric("ready", 0); #ifdef ENABLE_SYSTEMD -- 2.30.1