From fe5015f8ca597052f4446a1c59debb073b9010d9 Mon Sep 17 00:00:00 2001 From: khromenokroman Date: Thu, 22 Aug 2024 12:54:21 +0200 Subject: [PATCH] iox-#2330 Add libsystemd-dev to install dependencies This change updates the GitHub Action to include the libsystemd-dev package in the list of dependencies. Adding this package ensures that all necessary development libraries are available for builds. --- .../install-iceoryx-deps-and-clang/action.yml | 2 +- .../cmake/IceoryxPackageHelper.cmake | 2 +- .../iceoryx_posh/internal/roudi/roudi.hpp | 4 ++ iceoryx_posh/source/roudi/roudi.cpp | 48 +++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/.github/actions/install-iceoryx-deps-and-clang/action.yml b/.github/actions/install-iceoryx-deps-and-clang/action.yml index 5b4c51da03..64a28d3094 100644 --- a/.github/actions/install-iceoryx-deps-and-clang/action.yml +++ b/.github/actions/install-iceoryx-deps-and-clang/action.yml @@ -8,7 +8,7 @@ runs: sudo wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - sudo add-apt-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main" sudo apt-get update - sudo apt-get install -y libacl1-dev libncurses5-dev + sudo apt-get install -y libacl1-dev libncurses5-dev libsystemd-dev sudo apt-get install -y clang-format-15 clang-tidy-15 clang-tools-15 clang-15 lld sudo rm /usr/bin/clang sudo rm /usr/bin/clang++ diff --git a/iceoryx_platform/cmake/IceoryxPackageHelper.cmake b/iceoryx_platform/cmake/IceoryxPackageHelper.cmake index 49570e0df0..c5bd38227e 100644 --- a/iceoryx_platform/cmake/IceoryxPackageHelper.cmake +++ b/iceoryx_platform/cmake/IceoryxPackageHelper.cmake @@ -207,7 +207,7 @@ Macro(iox_add_executable) if ( QNX ) target_link_libraries(${IOX_TARGET} ${IOX_LIBS_QNX}) elseif ( LINUX ) - target_link_libraries(${IOX_TARGET} ${IOX_LIBS_LINUX}) + target_link_libraries(${IOX_TARGET} ${IOX_LIBS_LINUX} systemd) elseif ( APPLE ) target_link_libraries(${IOX_TARGET} ${IOX_LIBS_APPLE}) elseif ( WIN32 ) diff --git a/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp b/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp index 57b8e1303b..3c5c94ca90 100644 --- a/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp +++ b/iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp @@ -33,6 +33,7 @@ #include "iox/smart_lock.hpp" #include +#include #include namespace iox @@ -51,6 +52,8 @@ class RouDi PortManager& portManager, const config::RouDiConfig& roudiConfig) noexcept; + static constexpr uint16_t SIZE_ERROR_MESSAGE = 4096; + virtual ~RouDi() noexcept; /// @brief Triggers the discovery loop to run immediately instead of waiting for the next tick interval @@ -129,6 +132,7 @@ class RouDi private: std::thread m_monitoringAndDiscoveryThread; std::thread m_handleRuntimeMessageThread; + std::thread listen_thread_watchdog; // 8 protected: ProcessIntrospectionType m_processIntrospection; diff --git a/iceoryx_posh/source/roudi/roudi.cpp b/iceoryx_posh/source/roudi/roudi.cpp index 2289913c59..08bb26f04f 100644 --- a/iceoryx_posh/source/roudi/roudi.cpp +++ b/iceoryx_posh/source/roudi/roudi.cpp @@ -161,6 +161,15 @@ void RouDi::shutdown() noexcept // Postpone the IpcChannelThread in order to receive TERMINATION m_runHandleRuntimeMessageThread = false; + /* + * This is necessary to prevent the main thread from exiting before + * the 'listen_thread_watchdog' has finished, hence ensuring a + * proper termination of the entire application. + */ + if (listen_thread_watchdog.joinable()) { + listen_thread_watchdog.join(); + } + if (m_handleRuntimeMessageThread.joinable()) { IOX_LOG(DEBUG, "Joining 'IPC-msg-process' thread..."); @@ -254,6 +263,45 @@ void RouDi::processRuntimeMessages(runtime::IpcInterfaceCreator&& roudiIpcInterf IOX_LOG(INFO, "RouDi is ready for clients"); fflush(stdout); // explicitly flush 'stdout' for 'launch_testing' + /* + * We get information about how they are running. If as a unit, then we launch + * watchdog and send a notification about the launch, otherwise we do nothing + */ + const char* invocation_id = std::getenv("INVOCATION_ID"); + if (invocation_id != nullptr) + { + IOX_LOG(WARN, "Run APP in unit(systemd)"); + listen_thread_watchdog = std::thread([this] { + if (auto wdres = sd_notify(0, "READY=1") < 0) + { + std::array buf{}; + strerror_r(-static_cast(wdres), buf.data(), buf.size()); + IOX_LOG(ERROR, "WatchDogError: " << std::string(buf.data())); + return; + } + IOX_LOG(DEBUG, "WatchDog READY=1"); + + IOX_LOG(INFO, "Start watchdog"); + while (m_runHandleRuntimeMessageThread.load()) + { + if (auto wdres = sd_notify(0, "WATCHDOG=1") < 0) + { + std::array buf{}; + strerror_r(-static_cast(wdres), buf.data(), buf.size()); + IOX_LOG(ERROR, "WatchDogError: " << std::string(buf.data())); + return; + } + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + }); + if (pthread_setname_np(listen_thread_watchdog.native_handle(), "watchdog") != 0) + { + std::array buf{}; + strerror_r(errno, buf.data(), buf.size()); + IOX_LOG(ERROR, "Can not set name for thread watchdog: " << std::string(buf.data())); + } + } + while (m_runHandleRuntimeMessageThread) { // read RouDi's IPC channel