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.
This commit is contained in:
Niclas Antti 2018-11-09 14:28:11 +02:00
parent f29e5b65de
commit 1108132cbd
4 changed files with 17 additions and 4 deletions

View File

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

View File

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

View File

@ -27,7 +27,9 @@
#include <time.h>
#include <unistd.h>
#include <getopt.h>
#ifdef HAVE_SYSTEMD
#include <systemd/sd-daemon.h>
#endif
#include <set>
#include <map>
@ -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)
{

View File

@ -18,7 +18,9 @@
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef HAVE_SYSTEMD
#include <systemd/sd-daemon.h>
#endif
#include <vector>
#include <sstream>
@ -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);