summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmake/config.cmake2
-rw-r--r--cmake/deps.cmake10
-rw-r--r--src/CMakeLists.txt10
-rw-r--r--src/fastd.c42
-rw-r--r--src/fastd_config.h.in2
5 files changed, 43 insertions, 23 deletions
diff --git a/cmake/config.cmake b/cmake/config.cmake
index 8390bf2..e7e0f42 100644
--- a/cmake/config.cmake
+++ b/cmake/config.cmake
@@ -9,6 +9,7 @@ set(USE_BINDTODEVICE ${LINUX})
set(USE_PMTU ${LINUX})
set(USE_PKTINFO ${LINUX})
set(USE_PACKET_MARK ${LINUX})
+set(USE_SYSTEMD ${LINUX})
if(${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
set(USE_MULTIAF_BIND FALSE)
@@ -20,7 +21,6 @@ set(WITH_CAPABILITIES ${LINUX} CACHE BOOL "Include support for POSIX capabilitie
set(ENABLE_LIBSODIUM FALSE CACHE BOOL "Use libsodium instead of NaCl")
set(ENABLE_OPENSSL FALSE CACHE BOOL "Enable crypto implementations using OpenSSL")
-set(ENABLE_SYSTEMD FALSE CACHE BOOL "Enable systemd support")
set(WITH_CMDLINE_USER TRUE CACHE BOOL "Include support for setting user/group related options on the command line")
set(WITH_CMDLINE_LOGGING TRUE CACHE BOOL "Include support for setting logging related options on the command line")
diff --git a/cmake/deps.cmake b/cmake/deps.cmake
index 98c7582..d9dff1e 100644
--- a/cmake/deps.cmake
+++ b/cmake/deps.cmake
@@ -52,16 +52,6 @@ else(ENABLE_OPENSSL)
set(OPENSSL_CRYPTO_LDFLAGS_OTHER "")
endif(ENABLE_OPENSSL)
-if(ENABLE_SYSTEMD)
- pkg_check_modules(SYSTEMD_DAEMON REQUIRED libsystemd-daemon)
-else(ENABLE_SYSTEMD)
- set(SYSTEMD_DAEMON_INCLUDE_DIRS "")
- set(SYSTEMD_DAEMON_CFLAGS_OTHER "")
- set(SYSTEMD_DAEMON_LIBRARY_DIRS "")
- set(SYSTEMD_DAEMON_LIBRARIES "")
- set(SYSTEMD_DAEMON_LDFLAGS_OTHER "")
-endif(ENABLE_SYSTEMD)
-
if(WITH_CAPABILITIES)
find_package(CAP REQUIRED)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6ea65e8..e7fb940 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,8 +1,8 @@
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS _GNU_SOURCE)
-set(FASTD_CFLAGS "-pthread -std=c99 ${UECC_CFLAGS_OTHER} ${NACL_CFLAGS_OTHER} ${OPENSSL_CRYPTO_CFLAGS_OTHER} ${SYSTEMD_DAEMON_CFLAGS_OTHER} -Wall")
+set(FASTD_CFLAGS "-pthread -std=c99 ${UECC_CFLAGS_OTHER} ${NACL_CFLAGS_OTHER} ${OPENSSL_CRYPTO_CFLAGS_OTHER} -Wall")
include_directories(${FASTD_SOURCE_DIR} ${FASTD_BINARY_DIR}/src)
-link_directories(${UECC_LIBRARY_DIRS} ${NACL_LIBRARY_DIRS} ${OPENSSL_CRYPTO_LIBRARY_DIRS} ${SYSTEMD_DAEMON_LIBRARY_DIRS})
+link_directories(${UECC_LIBRARY_DIRS} ${NACL_LIBRARY_DIRS} ${OPENSSL_CRYPTO_LIBRARY_DIRS})
include(generate_version)
@@ -38,9 +38,9 @@ add_executable(fastd
${BISON_fastd_config_parse_OUTPUTS}
)
set_property(TARGET fastd PROPERTY COMPILE_FLAGS "${FASTD_CFLAGS}")
-set_property(TARGET fastd PROPERTY LINK_FLAGS "-pthread ${UECC_LDFLAGS_OTHER} ${NACL_LDFLAGS_OTHER} ${OPENSSL_CRYPTO_LDFLAGS_OTHER} ${SYSTEMD_DAEMON_LDFLAGS_OTHER}")
-set_property(TARGET fastd APPEND PROPERTY INCLUDE_DIRECTORIES ${CAP_INCLUDE_DIR} ${NACL_INCLUDE_DIRS} ${SYSTEMD_DAEMON_INCLUDE_DIRS})
-target_link_libraries(fastd protocols methods ciphers macs ${RT_LIBRARY} ${CAP_LIBRARY} ${UECC_LIBRARIES} ${NACL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES} ${SYSTEMD_DAEMON_LIBRARIES})
+set_property(TARGET fastd PROPERTY LINK_FLAGS "-pthread ${UECC_LDFLAGS_OTHER} ${NACL_LDFLAGS_OTHER} ${OPENSSL_CRYPTO_LDFLAGS_OTHER}")
+set_property(TARGET fastd APPEND PROPERTY INCLUDE_DIRECTORIES ${CAP_INCLUDE_DIR} ${NACL_INCLUDE_DIRS})
+target_link_libraries(fastd protocols methods ciphers macs ${RT_LIBRARY} ${CAP_LIBRARY} ${UECC_LIBRARIES} ${NACL_LIBRARIES} ${OPENSSL_CRYPTO_LIBRARIES})
add_dependencies(fastd version)
diff --git a/src/fastd.c b/src/fastd.c
index a6b8310..bbc5c61 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -51,8 +51,8 @@
#include <openssl/err.h>
#endif
-#ifdef ENABLE_SYSTEMD
-#include <systemd/sd-daemon.h>
+#ifdef USE_SYSTEMD
+#include <sys/un.h>
#endif
@@ -873,11 +873,42 @@ static int daemonize(fastd_context_t *ctx) {
return -1;
}
+#ifdef USE_SYSTEMD
+static void notify_systemd(fastd_context_t *ctx, const char *notify_socket) {
+ int fd;
+ struct sockaddr_un sa = {};
+
+ if ((notify_socket[0] != '@' && notify_socket[0] != '/') || notify_socket[1] == 0)
+ return;
+
+ fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
+ if (fd < 0)
+ return;
+
+ sa.sun_family = AF_UNIX;
+
+ strncpy(sa.sun_path, notify_socket, sizeof(sa.sun_path));
+ if (sa.sun_path[0] == '@')
+ sa.sun_path[0] = 0;
+
+ if (connect(fd, (struct sockaddr*)&sa, offsetof(struct sockaddr_un, sun_path) + strnlen(notify_socket, sizeof(sa.sun_path))) < 0) {
+ pr_debug_errno(ctx, "unable to connect to notify socket: connect");
+ close(fd);
+ return;
+ }
+
+ dprintf(fd, "READY=1\nMAINPID=%lu", (unsigned long) getpid());
+ pr_debug(ctx, "sent startup notification to systemd");
+
+ close(fd);
+}
+#endif
+
int main(int argc, char *argv[]) {
fastd_context_t ctx = {};
int status_fd = -1;
-#ifdef ENABLE_SYSTEMD
+#ifdef USE_SYSTEMD
char *notify_socket = getenv("NOTIFY_SOCKET");
if (notify_socket) {
@@ -959,10 +990,9 @@ int main(int argc, char *argv[]) {
write_pid(&ctx, getpid());
-#ifdef ENABLE_SYSTEMD
+#ifdef USE_SYSTEMD
if (notify_socket) {
- setenv("NOTIFY_SOCKET", notify_socket, 1);
- sd_notifyf(1, "READY=1\nMAINPID=%lu", (unsigned long) getpid());
+ notify_systemd(&ctx, notify_socket);
free(notify_socket);
}
#endif
diff --git a/src/fastd_config.h.in b/src/fastd_config.h.in
index 6851c25..4402139 100644
--- a/src/fastd_config.h.in
+++ b/src/fastd_config.h.in
@@ -37,6 +37,7 @@
#cmakedefine USE_PKTINFO
#cmakedefine USE_PACKET_MARK
#cmakedefine USE_MULTIAF_BIND
+#cmakedefine USE_SYSTEMD
#cmakedefine WITH_CAPABILITIES
@@ -48,7 +49,6 @@
#cmakedefine HAVE_LIBSODIUM
#cmakedefine ENABLE_OPENSSL
-#cmakedefine ENABLE_SYSTEMD
#define MAX_CONFIG_DEPTH @MAX_CONFIG_DEPTH_NUM@