diff --git a/CMakeLists.txt b/CMakeLists.txt index 341054289..290b6eeb5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ option(WARNINGS_AS_ERRORS "treat all warnings as errors. turn off for developmen option(TRACY_ROOT "include tracy profiler source" OFF) option(VENDOR_LIBSODIUM "use vendored libsodium" OFF) option(WITH_TESTS "build unit tests" ON) +option(WITH_SYSTEMD "enable systemd integration for sd_notify" OFF) include(cmake/target_link_libraries_system.cmake) include(cmake/add_import_library.cmake) @@ -46,8 +47,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") include(MacroEnsureOutOfSourceBuild) macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out-of-source build. Create a build directory and run 'cmake ${CMAKE_SOURCE_DIR} [options]'.") - - include(cmake/basic_definitions.cmake) if(MSVC_VERSION) @@ -228,6 +227,15 @@ if(JEMALLOC) set(MALLOC_LIB jemalloc) endif(JEMALLOC) + +if(WITH_SYSTEMD) + pkg_check_modules(SD REQUIRED libsystemd) + add_definitions(-DWITH_SYSTEMD) + include_directories(${SD_INCLUDE_DIRS}) + set(SD_LIBS ${SD_LDFLAGS}) +endif() + + set(ABSEIL_DIR vendor/abseil-cpp) include_directories(SYSTEM ${ABSEIL_DIR}) add_subdirectory(vendor/cxxopts) @@ -248,7 +256,7 @@ if(ANDROID) set(ANDROID_PLATFORM_SRC android/ifaddrs.c) endif(ANDROID) -set(LIBS ${MALLOC_LIB} ${FS_LIB} ${LIBUV_LIBRARY}) +set(LIBS ${MALLOC_LIB} ${FS_LIB} ${LIBUV_LIBRARY} ${SD_LIBS}) if(TRACY_ROOT) list(APPEND LIBS -ldl) endif() diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 9e067e7fa..3d2438de3 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -32,6 +32,9 @@ #if defined(ANDROID) || defined(IOS) #include #endif +#if defined(WITH_SYSTEMD) +#include +#endif namespace llarp { @@ -660,6 +663,10 @@ namespace llarp // LogDebug("tick router"); const auto now = Now(); +#if defined(WITH_SYSTEMD) + ::sd_notify(0, "WATCHDOG=1"); +#endif + routerProfiling().Tick(); if(ShouldReportStats(now)) @@ -1029,6 +1036,9 @@ namespace llarp ScheduleTicker(1000); _running.store(true); _startedAt = Now(); +#if defined(WITH_SYSTEMD) + ::sd_notify(0, "READY=1"); +#endif return _running; } diff --git a/llarp/util/thread/threading.hpp b/llarp/util/thread/threading.hpp index 4f88d639f..10ad84d3a 100644 --- a/llarp/util/thread/threading.hpp +++ b/llarp/util/thread/threading.hpp @@ -163,7 +163,9 @@ namespace llarp void TryAccess(F visit) const LOCKS_EXCLUDED(_access) { +#if defined(LOKINET_DEBUG) NullLock lock(&_access); +#endif visit(); }