]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
add support for systemd notification protocol
authorMichael Scherer <misc@zarb.org>
Thu, 20 Feb 2014 23:24:25 +0000 (00:24 +0100)
committerNick Mathewson <nickm@torproject.org>
Tue, 23 Dec 2014 16:06:01 +0000 (11:06 -0500)
This permit for now to signal readiness in a cleaner way
to systemd.

configure.ac
src/or/include.am
src/or/main.c
src/test/include.am

index 88b4da006de8e6caf53ca3ee71c872e09d9d0016..bec6196fab3f1c47093b3049c285457f1ef62391 100644 (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,37 @@ 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
+
 case $host in
    *-*-solaris* )
      AC_DEFINE(_REENTRANT, 1, [Define on some platforms to activate x_r() functions in time.h])
@@ -618,7 +651,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__)
index 643f7ce001d938314618fb1e4b302a3d2a5e22c3..fb1581c463b74a669538e078ce23bb0661de0dfe 100644 (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 = \
index 160bfa00e06616fcd47a5de7f702b343eb1dcd33..9fa62f89ef84779dee3bacf4309ac5efa28008e4 100644 (file)
 #include <event2/bufferevent.h>
 #endif
 
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
+
 void evdns_shutdown(int);
 
 /********* PROTOTYPES **********/
@@ -2043,6 +2047,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;
index d7a647940b638d90fe64e226f1ac3a507d181200..9db1587da7aa6d37db4b6c61874c6fa4abb7a3a4 100644 (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 \