Skip to content

provide an alternative path for robustlock files under QNX #1776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 23, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions src/cpp/rtps/transport/shared_mem/RobustLock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#include <boostconfig.hpp>
#include <boost/interprocess/detail/shared_dir_helpers.hpp>

#ifdef __QNXNTO__
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#endif // __QNXNTO__

namespace eprosima {
namespace fastdds {
namespace rtps {
Expand All @@ -41,20 +47,49 @@ class RobustLock

#else


static std::string get_file_path(
const std::string& filename)
{

#ifdef __QNXNTO__
static const char defaultdir[] = "/var/lock";
struct stat buf;
// check directory status
if (stat(defaultdir, &buf) != 0)
{
// directory not found, create it
if(errno == ENOENT)
{
mkdir(defaultdir, 0777);
}
// if another error then throw exception
else
{
std::string err("get_file_path() ");
err = err + strerror(errno);
throw std::runtime_error(err);
}
}
else
{
// directory exists do nothing
}
#else
// Default value from: glibc-2.29/sysdeps/unix/sysv/linux/shm-directory.c
static const char defaultdir[] = "/dev/shm/";
#endif // __QNXNTO__

std::string filepath;

#if defined(BOOST_INTERPROCESS_FILESYSTEM_BASED_POSIX_SHARED_MEMORY)
const bool add_leading_slash = false;
#elif defined(BOOST_INTERPROCESS_RUNTIME_FILESYSTEM_BASED_POSIX_SHARED_MEMORY)
const bool add_leading_slash = !boost::interprocess::shared_memory_object_detail::use_filesystem_based_posix();
#else
const bool add_leading_slash = true;
#endif
#endif // Platform dependent leading slash

if (add_leading_slash)
{
boost::interprocess::ipcdetail::add_leading_slash(filename.c_str(), filepath);
Expand All @@ -63,11 +98,10 @@ class RobustLock
{
boost::interprocess::ipcdetail::shared_filepath(filename.c_str(), filepath);
}

return defaultdir + filepath;
}
#endif // !defined(BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS)

#endif
};

} // namespace rtps
Expand Down