Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1054 removing undefined behavior since a message …
Browse files Browse the repository at this point in the history
…queue descriptor is not a file descriptor

Signed-off-by: Christian Eltzschig <me@elchris.org>
  • Loading branch information
elfenpiff committed Feb 4, 2022
1 parent cd27ecf commit f2b7ee9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion iceoryx_examples/iceperf/mq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void MQ::open(const std::string& name, const iox::posix::IpcChannelSide channelS
mode_t umaskSaved = umask(0);

auto mqCall = iox::posix::posixCall(iox_mq_open4)(name.c_str(), openFlags, m_filemode, &m_attributes)
.failureReturnValue(ERROR_CODE)
.failureReturnValue(INVALID_DESCRIPTOR)
.ignoreErrnos(ENOENT)
.evaluate()
.or_else([&](auto& r) {
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_examples/iceperf/mq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MQ : public IcePerfBase
static constexpr uint32_t MAX_MESSAGE_SIZE = 4 * IcePerfBase::ONE_KILOBYTE;
static constexpr uint32_t MAX_MESSAGES = 8;
static constexpr int32_t ERROR_CODE = -1;
static constexpr mqd_t INVALID_DESCRIPTOR = -1;
static constexpr mqd_t INVALID_DESCRIPTOR = std::numeric_limits<mqd_t>::max();

MQ(const std::string& publisherName, const std::string& subscriberName) noexcept;
/// @brief Cleans up outdated message queues, e.g. from a previous test
Expand Down
10 changes: 2 additions & 8 deletions iceoryx_hoofs/source/posix_wrapper/message_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ cxx::expected<mqd_t, IpcChannelError> MessageQueue::open(const IpcChannelName_t&
// the mask will be applied to the permissions, therefore we need to set it to 0
mode_t umaskSaved = umask(0);
auto mqCall = posixCall(iox_mq_open4)(l_name.c_str(), openFlags, m_filemode, &m_attributes)
.failureReturnValue(ERROR_CODE)
.failureReturnValue(INVALID_DESCRIPTOR)
.suppressErrorMessagesForErrnos(ENOENT)
.evaluate();

Expand Down Expand Up @@ -323,13 +323,7 @@ cxx::expected<IpcChannelError> MessageQueue::timedSend(const std::string& msg,

cxx::expected<bool, IpcChannelError> MessageQueue::isOutdated() noexcept
{
struct stat sb = {};
auto fstatCall = posixCall(fstat)(m_mqDescriptor, &sb).failureReturnValue(-1).evaluate();
if (fstatCall.has_error())
{
return createErrorFromErrnum(fstatCall.get_error().errnum);
}
return cxx::success<bool>(sb.st_nlink == 0);
return cxx::success<bool>(false);
}

cxx::error<IpcChannelError> MessageQueue::createErrorFromErrnum(const int32_t errnum) const noexcept
Expand Down

0 comments on commit f2b7ee9

Please sign in to comment.