Skip to content

Commit

Permalink
Refs #19036: Append username in the constructor of SharedMemGlobal
Browse files Browse the repository at this point in the history
Signed-off-by: elianalf <[email protected]>
  • Loading branch information
elianalf committed Jul 31, 2024
1 parent 8a244e9 commit d63e7c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 54 deletions.
58 changes: 16 additions & 42 deletions src/cpp/rtps/transport/shared_mem/SharedMemGlobal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,20 @@ class SharedMemGlobal
const std::string& domain_name)
: domain_name_(domain_name)
{
if (domain_name.length() > MAX_DOMAIN_NAME_LENGTH)
std::string username;
if(fastdds::dds::RETCODE_OK == SystemInfo::get_username(username))
{
domain_name_ = domain_name_ + "_" + username;
}
else
{
throw std::runtime_error("error: couldn't get username to generate port_segment_name");
}

if (domain_name_.length() > MAX_DOMAIN_NAME_LENGTH)
{
throw std::runtime_error(
domain_name +
domain_name_ +
" too long for domain name (max " +
std::to_string(MAX_DOMAIN_NAME_LENGTH) +
" characters");
Expand Down Expand Up @@ -909,17 +919,8 @@ class SharedMemGlobal
throw std::runtime_error("port is opened ReadShared");
}

std::string lock_name = std::string(node_->domain_name) + "_port" + std::to_string(node_->port_id);
std::string lock_name = std::string(node_->domain_name) + "_port" + std::to_string(node_->port_id) + "_el";

std::string username;
if(fastdds::dds::RETCODE_OK == SystemInfo::get_username(username))
{
lock_name = lock_name + "_" + username + "_el";
}
else
{
throw std::runtime_error("error: couldn't get username to generate port_segment_name");
}
read_exclusive_lock_ = std::unique_ptr<RobustExclusiveLock>(new RobustExclusiveLock(lock_name));
}

Expand All @@ -944,17 +945,8 @@ class SharedMemGlobal
uint32_t port_id,
const std::string& domain_name)
{
std::string lock_name = std::string(domain_name) + "_port" + std::to_string(port_id);
std::string lock_name = std::string(domain_name) + "_port" + std::to_string(port_id) + "_el";

std::string username;
if(fastdds::dds::RETCODE_OK == SystemInfo::get_username(username))
{
lock_name = lock_name + "_" + username + "_el";
}
else
{
throw std::runtime_error("error: couldn't get username to generate port_segment_name");
}
return std::unique_ptr<RobustExclusiveLock>(new RobustExclusiveLock(lock_name));
}

Expand All @@ -968,16 +960,8 @@ class SharedMemGlobal
try
{
// An exclusive port is zombie when it has a "_el" file & the file is not locked
lock_name = domain_name + "_port" + std::to_string(port_id);
std::string username;
if(fastdds::dds::RETCODE_OK == SystemInfo::get_username(username))
{
lock_name = lock_name + "_" + username + "_el";
}
else
{
throw std::runtime_error("error: couldn't get username to generate port_segment_name");
}
lock_name = domain_name + "_port" + std::to_string(port_id) + "_el";

RobustExclusiveLock zombie_test(lock_name, &was_lock_created);
// Lock acquired, did the file exist before the acquire?
if (!was_lock_created)
Expand Down Expand Up @@ -1085,16 +1069,6 @@ class SharedMemGlobal

auto port_segment_name = domain_name_ + "_port" + std::to_string(port_id);

std::string username;
if(fastdds::dds::RETCODE_OK == SystemInfo::get_username(username))
{
port_segment_name = port_segment_name + "_" + username;
}
else
{
throw std::runtime_error("error: couldn't get username to generate port_segment_name");
}

EPROSIMA_LOG_INFO(RTPS_TRANSPORT_SHM, THREADID << "Opening "
<< port_segment_name);

Expand Down
13 changes: 1 addition & 12 deletions src/cpp/rtps/transport/shared_mem/SharedMemManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "utils/collections/node_size_helpers.hpp"
#include "utils/shared_memory/RobustSharedLock.hpp"
#include "utils/shared_memory/SharedMemWatchdog.hpp"
#include <utils/SystemInfo.hpp>

namespace eprosima {
namespace fastdds {
Expand Down Expand Up @@ -538,17 +537,7 @@ class SharedMemManager :
{
// No collisions are most probable
segment_id_.generate();
segment_name_ = domain_name + "_" + segment_id_.to_string() ;

std::string username;
if(fastdds::dds::RETCODE_OK == SystemInfo::get_username(username))
{
segment_name_ = segment_name_ + "_" + username;
}
else
{
throw std::runtime_error("error: couldn't get username to generate segment_name");
}
segment_name_ = domain_name + "_" + segment_id_.to_string();

try
{
Expand Down

0 comments on commit d63e7c5

Please sign in to comment.