Merge pull request #6424 from delroth/traversal-watchdog
Add systemd watchdog support to the traversal server
This commit is contained in:
commit
ed2d749fb9
|
@ -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
|
||||
)
|
|
@ -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
|
||||
#
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -15,10 +15,16 @@
|
|||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifdef HAVE_LIBSYSTEMD
|
||||
#include <systemd/sd-daemon.h>
|
||||
#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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue