Skip to content

Commit

Permalink
additional logging added for shm memfile creation/handling (#1225)
Browse files Browse the repository at this point in the history
return values of ShmSetBufferCount evaluated in CSyncMemoryFile::Create function to state failed creation
  • Loading branch information
rex-schilasky authored Oct 25, 2023
1 parent 4439f91 commit 5f433cc
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 20 deletions.
4 changes: 2 additions & 2 deletions ecal/core/src/io/ecal_memfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace eCAL
if (!memfile::db::AddFile(name_, create_, create_ ? len_ + m_header.int_hdr_size : SIZEOF_PARTIAL_STRUCT(SInternalHeader, int_hdr_size), m_memfile_info))
{
#ifndef NDEBUG
printf("Could not create memory file: %s.\n\n", name_);
printf("Could not create memory file: %s.\n", name_);
#endif
return(false);
}
Expand All @@ -98,7 +98,7 @@ namespace eCAL
if(!m_memfile_mutex.Create(name_, m_auto_sanitizing))
{
#ifndef NDEBUG
printf("Could not create memory file mutex: %s.\n\n", name_);
printf("Could not create memory file mutex: %s.\n", name_);
#endif
return(false);
}
Expand Down
4 changes: 2 additions & 2 deletions ecal/core/src/io/ecal_memfile_sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ namespace eCAL
// create the memory file
if (!m_memfile.Create(m_memfile_name.c_str(), true, memfile_size))
{
Logging::Log(log_level_error, std::string(m_base_name + "::CSyncMemoryFile::Create - FAILED : ") + m_memfile_name);
Logging::Log(log_level_error, std::string("CSyncMemoryFile::Create FAILED : ") + m_memfile_name);
return false;
}

#ifndef NDEBUG
Logging::Log(log_level_debug2, std::string(m_base_name + "::CSyncMemoryFile::Create - SUCCESS : ") + m_memfile_name);
Logging::Log(log_level_debug2, std::string("CSyncMemoryFile::Create SUCCESS : ") + m_memfile_name);
#endif

// initialize memory file with empty header
Expand Down
1 change: 1 addition & 0 deletions ecal/core/src/io/ecal_memfile_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace eCAL

std::string GetName() const;
size_t GetSize() const;
bool IsCreated() const { return m_created; };

protected:
bool Create(const std::string& base_name_, size_t size_);
Expand Down
13 changes: 10 additions & 3 deletions ecal/core/src/io/linux/ecal_memfile_os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ namespace eCAL
umask(previous_umask); // reset umask to previous permissions
if (mem_file_info_.memfile == -1)
{
std::cout << "shm_open failed : " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl;
if(create_)
{
std::cerr << "shm_open failed to CREATE memory file (memfile::os::AllocFile): " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl;
}
else
{
std::cerr << "shm_open failed to OPEN memory file (memfile::os::AllocFile): " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl;
}
mem_file_info_.memfile = 0;
mem_file_info_.name = "";
mem_file_info_.exists = false;
Expand Down Expand Up @@ -101,7 +108,7 @@ namespace eCAL
// truncate file
if (::ftruncate(mem_file_info_.memfile, mem_file_info_.size) != 0)
{
std::cout << "ftruncate failed : " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl;
std::cerr << "ftruncate failed (memfile::os::MapFile): " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl;
}
}

Expand All @@ -113,7 +120,7 @@ namespace eCAL
if (mem_file_info_.mem_address == MAP_FAILED)
{
mem_file_info_.mem_address = nullptr;
std::cout << "mmap failed : " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl;
std::cerr << "mmap failed (memfile::os::MapFile): " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl;
return(false);
}
}
Expand Down
40 changes: 32 additions & 8 deletions ecal/core/src/readwrite/ecal_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,16 @@ namespace eCAL
{
case TLayer::eSendMode::smode_auto:
case TLayer::eSendMode::smode_on:
m_writer.udp_mc.Create(m_host_name, m_topic_name, m_topic_id);
if (m_writer.udp_mc.Create(m_host_name, m_topic_name, m_topic_id))
{
#ifndef NDEBUG
Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::UDP_MC_WRITER");
Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::UDP_MC_WRITER - SUCCESS");
#endif
}
else
{
Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Create::UDP_MC_WRITER - FAILED");
}
break;
case TLayer::eSendMode::smode_none:
case TLayer::eSendMode::smode_off:
Expand All @@ -1081,10 +1087,16 @@ namespace eCAL
{
case TLayer::eSendMode::smode_auto:
case TLayer::eSendMode::smode_on:
m_writer.shm.Create(m_host_name, m_topic_name, m_topic_id);
if (m_writer.shm.Create(m_host_name, m_topic_name, m_topic_id))
{
#ifndef NDEBUG
Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::SHM_WRITER");
Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::SHM_WRITER - SUCCESS");
#endif
}
else
{
Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Create::SHM_WRITER - FAILED");
}
break;
case TLayer::eSendMode::smode_none:
case TLayer::eSendMode::smode_off:
Expand All @@ -1105,10 +1117,16 @@ namespace eCAL
{
case TLayer::eSendMode::smode_auto:
case TLayer::eSendMode::smode_on:
m_writer.tcp.Create(m_host_name, m_topic_name, m_topic_id);
if (m_writer.tcp.Create(m_host_name, m_topic_name, m_topic_id))
{
#ifndef NDEBUG
Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::TCP_WRITER");
Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::TCP_WRITER - SUCCESS");
#endif
}
else
{
Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Create::TCP_WRITER - FAILED");
}
break;
case TLayer::eSendMode::smode_none:
case TLayer::eSendMode::smode_off:
Expand All @@ -1129,10 +1147,16 @@ namespace eCAL
{
case TLayer::eSendMode::smode_auto:
case TLayer::eSendMode::smode_on:
m_writer.inproc.Create(m_host_name, m_topic_name, m_topic_id);
if (m_writer.inproc.Create(m_host_name, m_topic_name, m_topic_id))
{
#ifndef NDEBUG
Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::INPROC_WRITER");
Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::INPROC_WRITER - SUCCESS");
#endif
}
else
{
Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Create::INPROC_WRITER - FAILED");
}
break;
default:
m_writer.inproc.Destroy();
Expand Down
17 changes: 12 additions & 5 deletions ecal/core/src/readwrite/ecal_writer_shm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ namespace eCAL
m_memory_file_attr.timeout_ack_ms = Config::GetMemfileAckTimeoutMs();

// initialize memory file buffer
SetBufferCount(m_buffer_count);

m_created = true;
m_created = SetBufferCount(m_buffer_count);;
return m_created;
}

Expand Down Expand Up @@ -124,12 +122,21 @@ namespace eCAL
memory_file_size = m_memory_file_attr.min_size;
}

// recreate memory file vector
// create memory file vector
m_memory_file_vec.clear();
while (m_memory_file_vec.size() < buffer_count_)
{
auto sync_memfile = std::make_shared<CSyncMemoryFile>(m_memfile_base_name, memory_file_size, m_memory_file_attr);
m_memory_file_vec.push_back(sync_memfile);
if (sync_memfile->IsCreated())
{
m_memory_file_vec.push_back(sync_memfile);
}
else
{
m_memory_file_vec.clear();
Logging::Log(log_level_error, "CDataWriterSHM::SetBufferCount - FAILED");
return false;
}
}

return true;
Expand Down

0 comments on commit 5f433cc

Please sign in to comment.