mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 05:03:43 +01:00
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.
This commit is contained in:
parent
aabaed6f49
commit
29ac883606
20
configure.ac
20
configure.ac
@ -138,6 +138,26 @@ if test x$enable_systemd = xyes -a x$have_systemd != xyes ; then
|
|||||||
AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
|
AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
AC_ARG_ENABLE(threads,
|
||||||
|
AS_HELP_STRING(--disable-threads, disable multi-threading support))
|
||||||
|
|
||||||
|
if test x$enable_threads = x; then
|
||||||
|
case $host in
|
||||||
|
*-*-solaris* )
|
||||||
|
# Don't try multithreading on solaris -- cpuworkers seem to lock.
|
||||||
|
AC_MSG_NOTICE([You are running Solaris; Sometimes threading makes
|
||||||
|
cpu workers lock up here, so I will disable threads.])
|
||||||
|
enable_threads="no";;
|
||||||
|
*)
|
||||||
|
enable_threads="yes";;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
ifdef([HAVE_SYSTEMD], [
|
||||||
|
AC_SEARCH_LIBS([sd_watchdog_enabled], [systemd-daemon],
|
||||||
|
[AC_DEFINE(HAVE_SYSTEMD_209,1,[Have systemd v209 or more])], [])
|
||||||
|
])
|
||||||
|
|
||||||
case $host in
|
case $host in
|
||||||
*-*-solaris* )
|
*-*-solaris* )
|
||||||
AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
|
AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
|
||||||
|
@ -1763,6 +1763,17 @@ second_elapsed_callback(periodic_timer_t *timer, void *arg)
|
|||||||
current_second = now; /* remember which second it is, for next time */
|
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
|
#ifndef USE_BUFFEREVENTS
|
||||||
/** Timer: used to invoke refill_callback(). */
|
/** Timer: used to invoke refill_callback(). */
|
||||||
static periodic_timer_t *refill_timer = NULL;
|
static periodic_timer_t *refill_timer = NULL;
|
||||||
@ -2031,6 +2042,24 @@ do_main_loop(void)
|
|||||||
tor_assert(second_timer);
|
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
|
#ifndef USE_BUFFEREVENTS
|
||||||
if (!refill_timer) {
|
if (!refill_timer) {
|
||||||
struct timeval refill_interval;
|
struct timeval refill_interval;
|
||||||
|
Loading…
Reference in New Issue
Block a user