Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add systemd watchdog support to the traversal server #6424

Merged
merged 2 commits into from Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev
traversal: add systemd watchdog support
  • Loading branch information
delroth committed Mar 8, 2018
commit 9e0739f5e578acc5289b13457690710fbadcdfdc
3 changes: 3 additions & 0 deletions Source/Core/Common/CMakeLists.txt
Expand Up @@ -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()
Expand Down
15 changes: 14 additions & 1 deletion Source/Core/Common/TraversalServer.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -450,5 +460,8 @@ int main()
HandlePacket(&packet, &raddr);
}
ResendPackets();
#ifdef HAVE_LIBSYSTEMD
sd_notify(0, "WATCHDOG=1");
#endif
}
}