diff --git a/CMakeLists.txt b/CMakeLists.txt index 502e6ba..fc4fb01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ option(LINK_SUPPORT "Allow hub linking" OFF) option(SSL_SUPPORT "Enable SSL support" ON) option(USE_OPENSSL "Use OpenSSL's SSL support" ON ) option(SQLITE_SUPPORT "Enable SQLite support" ON) -option(SYSTEMD_SUPPORT "Enable logging to the systemd journal" OFF) +option(SYSTEMD_SUPPORT "Enable systemd notify and journal logging" OFF) option(ADC_STRESS "Enable the stress tester client" OFF) find_package(Git) @@ -37,7 +37,8 @@ endif() if (SYSTEMD_SUPPORT) INCLUDE(FindPkgConfig) - pkg_search_module(JOURNAL REQUIRED libsystemd-journal) + pkg_search_module(SD_DAEMON REQUIRED libsystemd-daemon) + pkg_search_module(SD_JOURNAL REQUIRED libsystemd-journal) endif() if (MSVC) @@ -182,11 +183,14 @@ if(SSL_SUPPORT) endif() if (SYSTEMD_SUPPORT) - target_link_libraries(uhub ${JOURNAL_LIBRARIES}) - target_link_libraries(test ${JOURNAL_LIBRARIES}) - target_link_libraries(uhub-passwd ${JOURNAL_LIBRARIES}) - target_link_libraries(uhub-admin ${JOURNAL_LIBRARIES}) - include_directories(${JOURNAL_INCLUDE_DIRS}) + target_link_libraries(uhub ${SD_DAEMON_LIBRARIES}) + target_link_libraries(uhub ${SD_JOURNAL_LIBRARIES}) + target_link_libraries(test ${SD_DAEMON_LIBRARIES}) + target_link_libraries(test ${SD_JOURNAL_LIBRARIES}) + target_link_libraries(uhub-passwd ${SD_JOURNAL_LIBRARIES}) + target_link_libraries(uhub-admin ${SD_JOURNAL_LIBRARIES}) + include_directories(${SD_DAEMON_INCLUDE_DIRS}) + include_directories(${SD_JOURNAL_INCLUDE_DIRS}) add_definitions(-DSYSTEMD) endif() diff --git a/src/core/main.c b/src/core/main.c index 4f0fb26..ac2d2a8 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -19,6 +19,10 @@ #include "uhub.h" +#ifdef SYSTEMD +#include +#endif + static int arg_verbose = 5; static int arg_fork = 0; static int arg_check_config = 0; @@ -145,7 +149,16 @@ int main_loop() } #if !defined(WIN32) setup_signal_handlers(hub); -#endif +#ifdef SYSTEMD + /* Notify the service manager that this daemon has + * been successfully initalized and shall enter the + * main loop. + */ + sd_notifyf(0, "READY=1\n" + "MAINPID=%lu", (unsigned long) getpid()); +#endif /* SYSTEMD */ + +#endif /* ! WIN32 */ } hub_set_variables(hub, &acl);