summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-12-23 11:32:22 -0500
committerNick Mathewson <nickm@torproject.org>2014-12-23 11:32:22 -0500
commit9545569d73787211bf11355fe646e8918bdd19f0 (patch)
tree76d7979c02c954bc79200c88f0b627bc471640a2 /src/or
parentc6ac752353e6b03b2cbf2822d8fe2c60dfb03746 (diff)
parent7e1289b3eca37d72c87cc9a4a4a623e36095553e (diff)
downloadtor-9545569d73787211bf11355fe646e8918bdd19f0.tar.gz
tor-9545569d73787211bf11355fe646e8918bdd19f0.zip
Merge branch 'ticket11016'
Diffstat (limited to 'src/or')
-rw-r--r--src/or/include.am4
-rw-r--r--src/or/main.c42
2 files changed, 44 insertions, 2 deletions
diff --git a/src/or/include.am b/src/or/include.am
index 643f7ce001..fb1581c463 100644
--- a/src/or/include.am
+++ b/src/or/include.am
@@ -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 = \
diff --git a/src/or/main.c b/src/or/main.c
index 160bfa00e0..58e3ad3e4d 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -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;