Boost logo

Boost Testing :

From: Boris Gubenko (Boris.Gubenko_at_[hidden])
Date: 2007-11-13 23:40:18


Boris Gubenko wrote:
> I'll search interpocess library sources later today to see how the
> filename is formed, [...]

Here's what is going on:

On Tru64, <unistd.h> defines macro _POSIX_SHARED_MEMORY_OBJECTS as
an empty string while on HP-UX, it defines it with a value of 1.

Accordingly, <interprocess/detail/workaround.hpp> defines macro
BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS on HP-UX, but does
not define it on Tru64 :

   #if defined(_POSIX_SHARED_MEMORY_OBJECTS) && (_POSIX_SHARED_MEMORY_OBJECTS -
0 > 0)
      #define BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS
   #endif

If BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS is not defined, which
is the case on Tru64, the code in <interprocess/shared_memory_object.hpp>
prepends "/tmp/boost_interprocess/" to the filename, creates this
directory and calls open() function. In your example, the original name
is "/shm_name", so, after creating directory "/tmp/boost_interprocess/",
the Interprocess library calls open() function with filename
"/tmp/boost_interprocess//shm_name" and the call succeeds.

If BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS is defined, which is
the case on HP-UX, the code in <interprocess/shared_memory_object.hpp>
prepends slash to the filename, if filename does not begin with a slash,
and calls shm_open(). The intention, as far as I understand, is to pass
name argument to the shm_open() function such that all processes using
this name will refer to the same memory object. Unfortunately,
filesystem-based implementation of shm_open(), like the one on HP-UX,
treats such argument as an absolute pathname. In your example, shm_open()
is called with "/shm_name" and the call fails with EACCESS: a regular
user cannot create a file in file system root.

You might want to reconsider how you create name argument for shm_open()
function, at least on the platforms with filesystem-based implementation.
In your example, the name begins with a slash and Interprocess library
passes it to shm_open() untouched. But prepending the slash makes even
"innocent" call like

  shared_memory_object(create_only, "foo", read_write);

to fail. Perhaps, you can use name transformation algorithm which is
currently used on the platforms where
BOOST_INTERPROCESS_POSIX_SHARED_MEMORY_OBJECTS macro is not defined
on the platforms where this macro is defined as well. Just a thought.

Thanks,
  Boris


Boost-testing list run by mbergal at meta-comm.com