From f221fac02e39f8a965560741d46c15536c3a5cff Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Thu, 8 Mar 2018 06:00:40 +0000 Subject: [PATCH 1/2] cmake: check for optional libsystemd presence --- CMake/FindLibsystemd.cmake | 28 ++++++++++++++++++++++++++++ CMakeLists.txt | 8 ++++++++ 2 files changed, 36 insertions(+) create mode 100644 CMake/FindLibsystemd.cmake diff --git a/CMake/FindLibsystemd.cmake b/CMake/FindLibsystemd.cmake new file mode 100644 index 0000000000..f75558a444 --- /dev/null +++ b/CMake/FindLibsystemd.cmake @@ -0,0 +1,28 @@ +include(FindPkgConfig) +pkg_check_modules(PC_SYSTEMD QUIET "libsystemd") +if (PC_SYSTEMD_FOUND) + add_definitions(${PC_SYSTEMD_CFLAGS} ${PC_SYSTEMD_CFLAGS_OTHER}) +endif(PC_SYSTEMD_FOUND) + +find_path( + SYSTEMD_INCLUDE_DIRS + NAMES systemd/sd-daemon.h + HINTS ${PC_SYSTEMD_INCLUDEDIR} ${PC_SYSTEMD_INCLUDE_DIRS} +) + +find_library( + SYSTEMD_LIBRARIES + NAMES systemd + HINTS ${PC_SYSTEMD_LIBDIR} ${PC_SYSTEMD_LIBRARY_DIRS} +) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args( + SYSTEMD + REQUIRED_VARS SYSTEMD_LIBRARIES SYSTEMD_INCLUDE_DIRS +) +mark_as_advanced( + SYSTEMD_FOUND + SYSTEMD_LIBRARIES SYSTEMD_INCLUDE_DIRS +) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8090ff1a2b..14681c35ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -757,6 +757,14 @@ if(ENABLE_WX) endif() endif() +find_package(Libsystemd) +if(SYSTEMD_FOUND) + message(STATUS "libsystemd found, enabling traversal server watchdog support") + add_definitions(-DHAVE_LIBSYSTEMD) +else() + message(STATUS "libsystemd not found, disabling traversal server watchdog support") +endif() + ######################################## # Pre-build events: Define configuration variables and write SCM info header # From 9e0739f5e578acc5289b13457690710fbadcdfdc Mon Sep 17 00:00:00 2001 From: Pierre Bourdon Date: Thu, 8 Mar 2018 06:10:17 +0000 Subject: [PATCH 2/2] traversal: add systemd watchdog support --- Source/Core/Common/CMakeLists.txt | 3 +++ Source/Core/Common/TraversalServer.cpp | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index f4e0a4ff84..c4f153569d 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -131,6 +131,9 @@ endif() if(UNIX) # Posix networking code needs to be fixed for Windows add_executable(traversal_server TraversalServer.cpp) + if(SYSTEMD_FOUND) + target_link_libraries(traversal_server ${SYSTEMD_LIBRARIES}) + endif() if(HAIKU) target_link_libraries(traversal_server network) endif() diff --git a/Source/Core/Common/TraversalServer.cpp b/Source/Core/Common/TraversalServer.cpp index 825eee06a7..5da45a05fe 100644 --- a/Source/Core/Common/TraversalServer.cpp +++ b/Source/Core/Common/TraversalServer.cpp @@ -15,10 +15,16 @@ #include #include #include + +#ifdef HAVE_LIBSYSTEMD +#include +#endif + #include "Common/TraversalProto.h" #define DEBUG 0 #define NUMBER_OF_TRIES 5 +#define PORT 6262 static u64 currentTime; @@ -397,7 +403,7 @@ int main() addr.sin6_len = sizeof(addr); #endif addr.sin6_family = AF_INET6; - addr.sin6_port = htons(6262); + addr.sin6_port = htons(PORT); addr.sin6_flowinfo = 0; addr.sin6_addr = any; addr.sin6_scope_id = 0; @@ -419,6 +425,10 @@ int main() return 1; } +#ifdef HAVE_LIBSYSTEMD + sd_notifyf(0, "READY=1\nSTATUS=Listening on port %d", PORT); +#endif + while (true) { sockaddr_in6 raddr; @@ -450,5 +460,8 @@ int main() HandlePacket(&packet, &raddr); } ResendPackets(); +#ifdef HAVE_LIBSYSTEMD + sd_notify(0, "WATCHDOG=1"); +#endif } }