Skip to content

Commit

Permalink
iox-eclipse-iceoryx#2330 Add conditional compilation for systemd support
Browse files Browse the repository at this point in the history
Introduce preprocessor directives to conditionally enable systemd-related code and linking. This change allows for builds without systemd on Linux by checking for the USE_SYSTEMD flag, offering greater flexibility in different environments.
  • Loading branch information
khromenokroman committed Aug 22, 2024
1 parent 25155df commit e09617a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions 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} systemd)
target_link_libraries(${IOX_TARGET} ${IOX_LIBS_LINUX})
elseif ( APPLE )
target_link_libraries(${IOX_TARGET} ${IOX_LIBS_APPLE})
elseif ( WIN32 )
Expand Down Expand Up @@ -340,7 +340,12 @@ Macro(iox_add_library)
target_include_directories(${IOX_TARGET} PUBLIC ${IOX_PUBLIC_INCLUDES} PRIVATE ${IOX_PRIVATE_INCLUDES})

if ( LINUX )
target_link_libraries(${IOX_TARGET} PUBLIC ${IOX_PUBLIC_LIBS_LINUX} PRIVATE ${IOX_PRIVATE_LIBS_LINUX})
if(USE_SYSTEMD)
target_compile_definitions(${IOX_TARGET} PRIVATE USE_SYSTEMD=1)
target_link_libraries(${IOX_TARGET} PUBLIC ${IOX_PUBLIC_LIBS_LINUX} PRIVATE ${IOX_PRIVATE_LIBS_LINUX} systemd)
else()
target_link_libraries(${IOX_TARGET} PUBLIC ${IOX_PUBLIC_LIBS_LINUX} PRIVATE ${IOX_PRIVATE_LIBS_LINUX})
endif()
elseif ( APPLE )
target_link_libraries(${IOX_TARGET} PUBLIC ${IOX_PUBLIC_LIBS_APPLE} PRIVATE ${IOX_PRIVATE_LIBS_APPLE})
elseif ( QNX )
Expand Down
2 changes: 2 additions & 0 deletions iceoryx_posh/include/iceoryx_posh/internal/roudi/roudi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ class RouDi
private:
std::thread m_monitoringAndDiscoveryThread;
std::thread m_handleRuntimeMessageThread;
#ifdef USE_SYSTEMD
std::thread listen_thread_watchdog; // 8
#endif

protected:
ProcessIntrospectionType m_processIntrospection;
Expand Down
4 changes: 4 additions & 0 deletions iceoryx_posh/source/roudi/roudi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ void RouDi::shutdown() noexcept
// Postpone the IpcChannelThread in order to receive TERMINATION
m_runHandleRuntimeMessageThread = false;

#ifdef USE_SYSTEMD
/*
* This is necessary to prevent the main thread from exiting before
* the 'listen_thread_watchdog' has finished, hence ensuring a
Expand All @@ -169,6 +170,7 @@ void RouDi::shutdown() noexcept
if (listen_thread_watchdog.joinable()) {
listen_thread_watchdog.join();
}
#endif

if (m_handleRuntimeMessageThread.joinable())
{
Expand Down Expand Up @@ -263,6 +265,7 @@ void RouDi::processRuntimeMessages(runtime::IpcInterfaceCreator&& roudiIpcInterf
IOX_LOG(INFO, "RouDi is ready for clients");
fflush(stdout); // explicitly flush 'stdout' for 'launch_testing'

#ifdef USE_SYSTEMD
/*
* 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
Expand Down Expand Up @@ -301,6 +304,7 @@ void RouDi::processRuntimeMessages(runtime::IpcInterfaceCreator&& roudiIpcInterf
IOX_LOG(ERROR, "Can not set name for thread watchdog: " << std::string(buf.data()));
}
}
#endif

while (m_runHandleRuntimeMessageThread)
{
Expand Down

0 comments on commit e09617a

Please sign in to comment.