From 1108132cbdfa5b76c560fb082a71cb2c30ae8eb3 Mon Sep 17 00:00:00 2001 From: Niclas Antti Date: Fri, 9 Nov 2018 14:28:11 +0200 Subject: [PATCH] MXS-2057 Do not require systemd libraries Exclude systemd usage if the library is not installed. Only excluding what is necessary. This keeps the object size the same and still compiles most of the code. --- cmake/CheckPlatform.cmake | 6 ++++++ maxutils/maxbase/src/CMakeLists.txt | 6 +++--- server/core/gateway.cc | 4 ++++ server/core/routingworker.cc | 5 ++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cmake/CheckPlatform.cmake b/cmake/CheckPlatform.cmake index 199c4e4e6..574b0f04a 100644 --- a/cmake/CheckPlatform.cmake +++ b/cmake/CheckPlatform.cmake @@ -41,6 +41,12 @@ if(NOT HAVE_LIBPTHREAD) message(FATAL_ERROR "Could not find libpthread") endif() +# systemd libraries are optional +find_library(HAVE_SYSTEMD NAMES systemd) +if(HAVE_SYSTEMD) + add_definitions(-DHAVE_SYSTEMD=1) +endif() + # The XSI version of strerror_r return an int and the GNU version a char* check_cxx_source_compiles(" #define _GNU_SOURCE 1 diff --git a/maxutils/maxbase/src/CMakeLists.txt b/maxutils/maxbase/src/CMakeLists.txt index 60ca60b8b..f6186ebd5 100644 --- a/maxutils/maxbase/src/CMakeLists.txt +++ b/maxutils/maxbase/src/CMakeLists.txt @@ -15,9 +15,9 @@ add_library(maxbase STATIC average.cc ) -target_link_libraries(maxbase - systemd -) +if(HAVE_SYSTEMD) +target_link_libraries(maxbase systemd) +endif() set_target_properties(maxbase PROPERTIES VERSION "1.0.0" LINK_FLAGS -Wl,-z,defs) add_subdirectory(test) diff --git a/server/core/gateway.cc b/server/core/gateway.cc index d53c931ba..28b052931 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -27,7 +27,9 @@ #include #include #include +#ifdef HAVE_SYSTEMD #include +#endif #include #include @@ -1769,12 +1771,14 @@ int main(int argc, char** argv) cnf->log_target = MXB_LOG_TARGET_STDOUT; } +#ifdef HAVE_SYSTEMD // Systemd watchdog. Must be called in the initial thread */ uint64_t systemd_interval; // in microseconds if (sd_watchdog_enabled(false, &systemd_interval) > 0) { RoutingWorker::set_watchdog_interval(systemd_interval); } +#endif if (!daemon_mode) { diff --git a/server/core/routingworker.cc b/server/core/routingworker.cc index e42c0ec7a..72096dbff 100644 --- a/server/core/routingworker.cc +++ b/server/core/routingworker.cc @@ -18,7 +18,9 @@ #include #include #include +#ifdef HAVE_SYSTEMD #include +#endif #include #include @@ -1017,8 +1019,9 @@ void RoutingWorker::check_systemd_watchdog() if (all_alive) { s_watchdog_next_check = now + s_watchdog_interval; - MXS_NOTICE("sd_notify\n"); +#ifdef HAVE_SYSTEMD sd_notify(false, "WATCHDOG=1"); +#endif std::for_each(this_unit.ppWorkers, this_unit.ppWorkers + this_unit.nWorkers, [](RoutingWorker* rw) { rw->m_alive.store(false, std::memory_order_relaxed);