From 5c03429b4e11c5ae0c3a74825bad643be775cbe6 Mon Sep 17 00:00:00 2001 From: Mathias Kraus Date: Mon, 12 Feb 2024 18:21:02 +0100 Subject: [PATCH] iox-#2185 Use 'iox1' prefix for unique roudi lock --- .../iceoryx_posh/iceoryx_posh_types.hpp | 4 ++- .../memory/iceoryx_roudi_memory_manager.hpp | 19 +------------- .../memory/iceoryx_roudi_memory_manager.cpp | 25 ++++++++++++++++++- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp b/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp index 678b9ca929..3e7deb853f 100644 --- a/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp +++ b/iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp @@ -196,6 +196,8 @@ struct DefaultChunkQueueConfig static constexpr uint64_t MAX_QUEUE_CAPACITY = MAX_SUBSCRIBER_QUEUE_CAPACITY; }; +constexpr const char ICEORYX_RESOURCE_PREFIX[] = "iox1"; + // alias for string using RuntimeName_t = string; using NodeName_t = string; @@ -214,7 +216,7 @@ namespace roudi // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers) using ConfigFilePathString_t = string<1024>; -constexpr const char ROUDI_LOCK_NAME[] = "iox-unique-roudi"; +constexpr const char ROUDI_LOCK_NAME[] = "unique_roudi"; constexpr const char IPC_CHANNEL_ROUDI_NAME[] = "roudi"; /// shared memory segment for the iceoryx management data diff --git a/iceoryx_posh/include/iceoryx_posh/roudi/memory/iceoryx_roudi_memory_manager.hpp b/iceoryx_posh/include/iceoryx_posh/roudi/memory/iceoryx_roudi_memory_manager.hpp index cc819f2f7a..9f8ff272c5 100644 --- a/iceoryx_posh/include/iceoryx_posh/roudi/memory/iceoryx_roudi_memory_manager.hpp +++ b/iceoryx_posh/include/iceoryx_posh/roudi/memory/iceoryx_roudi_memory_manager.hpp @@ -62,24 +62,7 @@ class IceOryxRouDiMemoryManager : public RouDiMemoryInterface private: // in order to prevent a second RouDi to cleanup the memory resources of a running RouDi, this resources are // protected by a file lock - FileLock fileLock = - std::move(FileLockBuilder() - .name(ROUDI_LOCK_NAME) - .permission(iox::perms::owner_read | iox::perms::owner_write) - .create() - .or_else([](auto& error) { - if (error == FileLockError::LOCKED_BY_OTHER_PROCESS) - { - IOX_LOG(FATAL, "Could not acquire lock, is RouDi still running?"); - IOX_REPORT_FATAL(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__ROUDI_STILL_RUNNING); - } - else - { - IOX_LOG(FATAL, "Error occurred while acquiring file lock named " << ROUDI_LOCK_NAME); - IOX_REPORT_FATAL(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__COULD_NOT_ACQUIRE_FILE_LOCK); - } - }) - .value()); + FileLock m_fileLock; PortPoolMemoryBlock m_portPoolBlock; optional m_portPool; diff --git a/iceoryx_posh/source/roudi/memory/iceoryx_roudi_memory_manager.cpp b/iceoryx_posh/source/roudi/memory/iceoryx_roudi_memory_manager.cpp index 6b81e2b1bb..7de2f02bdf 100644 --- a/iceoryx_posh/source/roudi/memory/iceoryx_roudi_memory_manager.cpp +++ b/iceoryx_posh/source/roudi/memory/iceoryx_roudi_memory_manager.cpp @@ -23,7 +23,30 @@ namespace iox namespace roudi { IceOryxRouDiMemoryManager::IceOryxRouDiMemoryManager(const RouDiConfig_t& roudiConfig) noexcept - : m_defaultMemory(roudiConfig) + : m_fileLock(std::move( + FileLockBuilder() + .name([] { + iox::string<1> uniqueRoudiIdString{TruncateToCapacity, + iox::convert::toString(DEFAULT_UNIQUE_ROUDI_ID).c_str()}; + auto lockName = concatenate(ICEORYX_RESOURCE_PREFIX, "_", uniqueRoudiIdString, "_", ROUDI_LOCK_NAME); + return lockName; + }()) + .permission(iox::perms::owner_read | iox::perms::owner_write) + .create() + .or_else([](auto& error) { + if (error == FileLockError::LOCKED_BY_OTHER_PROCESS) + { + IOX_LOG(FATAL, "Could not acquire lock, is RouDi still running?"); + IOX_REPORT_FATAL(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__ROUDI_STILL_RUNNING); + } + else + { + IOX_LOG(FATAL, "Error occurred while acquiring file lock named " << ROUDI_LOCK_NAME); + IOX_REPORT_FATAL(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__COULD_NOT_ACQUIRE_FILE_LOCK); + } + }) + .value())) + , m_defaultMemory(roudiConfig) { m_defaultMemory.m_managementShm.addMemoryBlock(&m_portPoolBlock).or_else([](auto) { IOX_REPORT_FATAL(PoshError::ICEORYX_ROUDI_MEMORY_MANAGER__FAILED_TO_ADD_PORTPOOL_MEMORY_BLOCK);