Merge pull request #6424 from delroth/traversal-watchdog

Add systemd watchdog support to the traversal server
This commit is contained in:
Léo Lam 2018-03-08 17:29:45 +01:00 committed by GitHub
commit ed2d749fb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 1 deletions

View File

@ -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
)

View File

@ -757,6 +757,14 @@ if(ENABLE_WX)
endif() endif()
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 # Pre-build events: Define configuration variables and write SCM info header
# #

View File

@ -131,6 +131,9 @@ endif()
if(UNIX) if(UNIX)
# Posix networking code needs to be fixed for Windows # Posix networking code needs to be fixed for Windows
add_executable(traversal_server TraversalServer.cpp) add_executable(traversal_server TraversalServer.cpp)
if(SYSTEMD_FOUND)
target_link_libraries(traversal_server ${SYSTEMD_LIBRARIES})
endif()
if(HAIKU) if(HAIKU)
target_link_libraries(traversal_server network) target_link_libraries(traversal_server network)
endif() endif()

View File

@ -15,10 +15,16 @@
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include <vector> #include <vector>
#ifdef HAVE_LIBSYSTEMD
#include <systemd/sd-daemon.h>
#endif
#include "Common/TraversalProto.h" #include "Common/TraversalProto.h"
#define DEBUG 0 #define DEBUG 0
#define NUMBER_OF_TRIES 5 #define NUMBER_OF_TRIES 5
#define PORT 6262
static u64 currentTime; static u64 currentTime;
@ -397,7 +403,7 @@ int main()
addr.sin6_len = sizeof(addr); addr.sin6_len = sizeof(addr);
#endif #endif
addr.sin6_family = AF_INET6; addr.sin6_family = AF_INET6;
addr.sin6_port = htons(6262); addr.sin6_port = htons(PORT);
addr.sin6_flowinfo = 0; addr.sin6_flowinfo = 0;
addr.sin6_addr = any; addr.sin6_addr = any;
addr.sin6_scope_id = 0; addr.sin6_scope_id = 0;
@ -419,6 +425,10 @@ int main()
return 1; return 1;
} }
#ifdef HAVE_LIBSYSTEMD
sd_notifyf(0, "READY=1\nSTATUS=Listening on port %d", PORT);
#endif
while (true) while (true)
{ {
sockaddr_in6 raddr; sockaddr_in6 raddr;
@ -450,5 +460,8 @@ int main()
HandlePacket(&packet, &raddr); HandlePacket(&packet, &raddr);
} }
ResendPackets(); ResendPackets();
#ifdef HAVE_LIBSYSTEMD
sd_notify(0, "WATCHDOG=1");
#endif
} }
} }