Skip to content

Commit

Permalink
iox-#2330 Add libsystemd-dev to install dependencies
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
khromenokroman committed Aug 22, 2024
1 parent 8a2a18f commit fe5015f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/actions/install-iceoryx-deps-and-clang/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_platform/cmake/IceoryxPackageHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
4 changes: 4 additions & 0 deletions iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "iox/smart_lock.hpp"

#include <cstdint>
#include <systemd/sd-daemon.h>
#include <thread>

namespace iox
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
48 changes: 48 additions & 0 deletions iceoryx_posh/source/roudi/roudi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
Expand Down Expand Up @@ -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<char, SIZE_ERROR_MESSAGE> buf{};
strerror_r(-static_cast<int>(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<char, SIZE_ERROR_MESSAGE> buf{};
strerror_r(-static_cast<int>(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<char, SIZE_ERROR_MESSAGE> 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
Expand Down

0 comments on commit fe5015f

Please sign in to comment.