From 907d266d32c9a82cfc3646ed6746a0b4cc7de958 Mon Sep 17 00:00:00 2001 From: Felipe Sateler Date: Tue, 11 Sep 2018 19:33:24 -0300 Subject: [PATCH] Notify tunnel up to systemd with sd_notify Allows usage of Type=notify systemd service types. Fixes: #229 --- Makefile.am | 4 ++-- configure.ac | 1 + src/tunnel.c | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 12649122..b8b70367 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,8 +9,8 @@ openfortivpn_SOURCES = src/config.c src/config.h src/hdlc.c src/hdlc.h \ openfortivpn_CFLAGS = -Wall --pedantic -std=gnu99 openfortivpn_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" -openfortivpn_CPPFLAGS += $(OPENSSL_CFLAGS) -openfortivpn_LDADD = $(OPENSSL_LIBS) +openfortivpn_CPPFLAGS += $(OPENSSL_CFLAGS) $(LIBSYSTEMD_CFLAGS) +openfortivpn_LDADD = $(OPENSSL_LIBS) $(LIBSYSTEMD_LIBS) DISTCHECK_CONFIGURE_FLAGS = CFLAGS=-Werror diff --git a/configure.ac b/configure.ac index a59c7a29..2c70494d 100644 --- a/configure.ac +++ b/configure.ac @@ -21,6 +21,7 @@ AM_SILENT_RULES([yes]) PKG_CHECK_MODULES(OPENSSL, [libcrypto >= 0.9.8 libssl >= 0.9.8], [], [AC_MSG_ERROR([Cannot find OpenSSL 0.9.8 or higher.])]) AC_CHECK_LIB([pthread], [pthread_create], [], [AC_MSG_ERROR([Cannot find libpthread.])]) AC_CHECK_LIB([util], [forkpty], [], [AC_MSG_ERROR([Cannot find libutil.])]) +PKG_CHECK_MODULES(LIBSYSTEMD, [libsystemd], [AC_DEFINE(HAVE_SYSTEMD)], [ ]) # Checks for header files. AC_CHECK_HEADERS([arpa/inet.h assert.h ctype.h errno.h fcntl.h getopt.h ifaddrs.h limits.h mach/mach.h netdb.h net/if.h netinet/in.h netinet/tcp.h net/route.h pty.h semaphore.h signal.h stdarg.h stddef.h stdint.h stdio.h stdlib.h string.h strings.h sys/ioctl.h syslog.h sys/socket.h sys/stat.h sys/time.h sys/types.h sys/wait.h termios.h unistd.h util.h]) diff --git a/src/tunnel.c b/src/tunnel.c index 497295b1..3b594452 100644 --- a/src/tunnel.c +++ b/src/tunnel.c @@ -50,6 +50,9 @@ #include #include #include +#if HAVE_SYSTEMD +#include +#endif struct ofv_varr { unsigned cap; // current capacity @@ -101,6 +104,10 @@ static int on_ppp_if_up(struct tunnel *tunnel) log_info("Tunnel is up and running.\n"); +#if HAVE_SYSTEMD + sd_notify(0, "READY=1"); +#endif + return 0; }