Merge branch 'ticket11016'

This commit is contained in:
Nick Mathewson 2014-12-23 11:32:22 -05:00
commit 9545569d73
5 changed files with 108 additions and 5 deletions

6
changes/ticket11016 Normal file
View File

@ -0,0 +1,6 @@
o Minor features (systemd):
- Where supported, when running with systemd, report successful
startup to systemd. Part of ticket 11016. Patch by Michael
Scherer.
- When running with systemd, support systemd watchdog messages.
Part of ticket 11016. Patch by Michael Scherer.

View File

@ -12,6 +12,8 @@ AC_CONFIG_HEADERS([orconfig.h])
AC_CANONICAL_HOST
PKG_PROG_PKG_CONFIG
if test -f /etc/redhat-release ; then
if test -f /usr/kerberos/include ; then
CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
@ -105,6 +107,57 @@ AC_ARG_ENABLE(upnp,
* ) AC_MSG_ERROR(bad value for --enable-upnp) ;;
esac], [upnp=false])
# systemd notify support
AC_ARG_ENABLE(systemd,
AS_HELP_STRING(--enable-systemd, enable systemd notification support),
[case "${enableval}" in
yes) systemd=true ;;
no) systemd=false ;;
* ) AC_MSG_ERROR(bad value for --enable-systemd) ;;
esac], [systemd=auto])
# systemd support
if test x$enable_systemd = xfalse ; then
have_systemd=no;
else
PKG_CHECK_MODULES(SYSTEMD,
[libsystemd-daemon],
have_systemd=yes,
have_systemd=no)
fi
if test x$have_systemd = xyes; then
AC_DEFINE(HAVE_SYSTEMD,1,[Have systemd])
TOR_SYSTEMD_LIBS="-lsystemd-daemon"
fi
AC_SUBST(TOR_SYSTEMD_LIBS)
if test x$enable_systemd = xyes -a x$have_systemd != xyes ; then
AC_MSG_ERROR([Explicitly requested systemd support, but systemd not found])
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
*-*-solaris* )
AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
@ -618,7 +671,7 @@ dnl since sometimes the linker will like an option but not be willing to
dnl use it with a build of a library.
all_ldflags_for_check="$TOR_LDFLAGS_zlib $TOR_LDFLAGS_openssl $TOR_LDFLAGS_libevent"
all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
all_libs_for_check="$TOR_ZLIB_LIBS $TOR_LIB_MATH $TOR_LIBEVENT_LIBS $TOR_OPENSSL_LIBS $TOR_SYSTEMD_LIBS $TOR_LIB_WS32 $TOR_LIB_GDI"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [
#if !defined(__clang__)

View File

@ -111,7 +111,7 @@ src_or_tor_LDADD = src/or/libtor.a src/common/libor.a \
src/common/libor-crypto.a $(LIBDONNA) \
src/common/libor-event.a \
@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ \
@TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@
@TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@ @TOR_SYSTEMD_LIBS@
if COVERAGE_ENABLED
src_or_tor_cov_SOURCES = src/or/tor_main.c
@ -122,7 +122,7 @@ src_or_tor_cov_LDADD = src/or/libtor-testing.a src/common/libor-testing.a \
src/common/libor-crypto-testing.a $(LIBDONNA) \
src/common/libor-event-testing.a \
@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ @TOR_OPENSSL_LIBS@ \
@TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@
@TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@ @TOR_SYSTEMD_LIBS@
endif
ORHEADERS = \

View File

@ -75,6 +75,10 @@
#include <event2/bufferevent.h>
#endif
#ifdef HAVE_SYSTEMD
#include <systemd/sd-daemon.h>
#endif
void evdns_shutdown(int);
/********* PROTOTYPES **********/
@ -1759,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;
@ -2027,6 +2042,28 @@ 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) > 0) {
if (! systemd_watchdog_timer) {
struct timeval watchdog;
/* The manager will "act on" us if we don't send them a notification
* every 'watchdog_delay' microseconds. So, send notifications twice
* that often. */
watchdog_delay /= 2;
watchdog.tv_sec = watchdog_delay / 1000000;
watchdog.tv_usec = watchdog_delay % 1000000;
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;
@ -2043,6 +2080,11 @@ do_main_loop(void)
}
#endif
#ifdef HAVE_SYSTEMD
log_notice(LD_GENERAL, "Signaling readyness to systemd");
sd_notify(0, "READY=1");
#endif
for (;;) {
if (nt_service_is_stopping())
return 0;

View File

@ -68,7 +68,8 @@ src_test_test_LDADD = src/or/libtor-testing.a src/common/libor-testing.a \
src/common/libor-crypto-testing.a $(LIBDONNA) \
src/common/libor-event-testing.a src/trunnel/libor-trunnel-testing.a \
@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \
@TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@
@TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@ \
@TOR_SYSTEMD_LIBS@
src_test_bench_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ \
@TOR_LDFLAGS_libevent@
@ -76,7 +77,8 @@ src_test_bench_LDADD = src/or/libtor.a src/common/libor.a \
src/common/libor-crypto.a $(LIBDONNA) \
src/common/libor-event.a \
@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \
@TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@
@TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@ \
@TOR_SYSTEMD_LIBS@
noinst_HEADERS+= \
src/test/fakechans.h \