1

How can i redirect creation of Boost message queue file to user specified directory. I am using ubuntu. Currently it gets created on /dev/shm location. File is same as message queue name. I tried defining macro BOOST_INTERPROCESS_SHARED_DIR_FUNC and implemented function get_shared_dir. But it is not working. Below is my code : File : message_queue_dir_path.h

    #include <string>
    namespace boost {
        namespace interprocess {
            namespace ipcdetail {
                void get_shared_dir(std::&shared_dir){
                    shared_dir = "/home/username/message_queue_dir";
                }
           }
       }
    }

And define macro in BOOST_INTERPROCESS_SHARED_DIR_FUNC in compilation. But still it is not creating the file at give location. It goes to /dev/shm

Kunal
  • 564
  • 5
  • 12

1 Answers1

2

I debugged similar situation on CentOS 7 and my findings are: on Linux it is not possible to change shared_dir using get_shared_dir. It will be in /dev/shm (or wherever is your tmpfs mounted).

Reason for that is on Linux boost message_queue is using "shm_open" internally. And shm_open allows only for "object name", not a file path.

On Windows your solution works as a charm.

If you would like to look yourself at the code you can found it in boost\interprocess\shared_memory_object.hpp, function shared_memory_object::priv_open_or_create.

Related issue: how do i change the shm_open path?

mikel
  • 21
  • 4