diff options
author | Michael Scherer <misc@zarb.org> | 2014-12-23 11:22:42 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-12-23 11:22:42 -0500 |
commit | 29ac883606d6d5ebfdcc2efceb2b4b60ee6a8916 (patch) | |
tree | 0a69e3e1623084217b7348b6207fa9ebc190000e /src | |
parent | aabaed6f497335b81f18347e626ff3d9ae7799d5 (diff) | |
download | tor-29ac883606d6d5ebfdcc2efceb2b4b60ee6a8916.tar.gz tor-29ac883606d6d5ebfdcc2efceb2b4b60ee6a8916.zip |
Add support for systemd watchdog protocol
It work by notifying systemd on a regular basis. If
there is no notification, the daemon is restarted.
This requires a version newer than the 209 version
of systemd, as it is not supported before.
Diffstat (limited to 'src')
-rw-r--r-- | src/or/main.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/or/main.c b/src/or/main.c index 9fa62f89ef..5a17212da6 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -1763,6 +1763,17 @@ second_elapsed_callback(periodic_timer_t *timer, void *arg) current_second = now; /* remember which second it is, for next time */ } +#ifdef HAVE_SYSTEMD_209 +static periodic_timer_t *systemd_watchdog_timer = NULL; + +/** Libevent callback: invoked to reset systemd watchdog. */ +static void +systemd_watchdog_callback(periodic_timer_t *timer, void *arg) +{ + sd_notify(1, "WATCHDOG=1"); +} +#endif + #ifndef USE_BUFFEREVENTS /** Timer: used to invoke refill_callback(). */ static periodic_timer_t *refill_timer = NULL; @@ -2031,6 +2042,24 @@ do_main_loop(void) tor_assert(second_timer); } +#ifdef HAVE_SYSTEMD_209 + uint64_t watchdog_delay; + /* set up systemd watchdog notification. */ + if (sd_watchdog_enabled(1, &watchdog_delay)) { + if (! systemd_watchdog_timer) { + struct timeval watchdog; + watchdog.tv_sec = 0; + watchdog.tv_usec = watchdog_delay/2; + + systemd_watchdog_timer = periodic_timer_new(tor_libevent_get_base(), + &watchdog, + systemd_watchdog_callback, + NULL); + tor_assert(systemd_watchdog_timer); + } + } +#endif + #ifndef USE_BUFFEREVENTS if (!refill_timer) { struct timeval refill_interval; |