Skip to content

Commit

Permalink
iox-eclipse-iceoryx#2185 Use 'iox1' prefix for unique roudi lock
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Feb 19, 2024
1 parent b2e4137 commit 5c03429
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
4 changes: 3 additions & 1 deletion iceoryx_posh/include/iceoryx_posh/iceoryx_posh_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MAX_RUNTIME_NAME_LENGTH>;
using NodeName_t = string<build::IOX_MAX_NODE_NAME_LENGTH>;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PortPool> m_portPool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5c03429

Please sign in to comment.