Boost logo

Boost :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2007-11-14 12:13:39


Boris Gubenko wrote:
> 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.

According to the opengroup specification:

http://www.opengroup.org/onlinepubs/007908799/xsh/shm_open.html

The name argument conforms to the construction rules for a pathname. If
name begins with the slash character, then processes calling shm_open()
with the same value of name refer to the same shared memory object, as
long as that name has not been removed. If name does not begin with the
slash character, the effect is implementation-dependent. The
interpretation of slash characters other than the leading slash
character in name is implementation-dependent.

So:

-> If leading slash is not used, two processes might not access the same
memory.

-> If there are more slashes than the leading one, both processes refer
the same shared memory but that name is not portable accross OSs.

-> The only portable (between OSs) name is a name that only has a
leading slash.

In all POSIX books the recommended name format is "/name", (in fact,
some systems don't accept a name without the leading slash). In Linux
/name leading to a shared memory created in /dev/shm/name.

Then I have two options:

-> Transform internally the name for HP-UX to a directory where everyone
can create shared memory. What should I choose? /tmp?
-> Change names used in tests for HP-UX for something that works.

It's a shame that there is no portable shared memory name for every
system ;-), because many pages, like these:

http://www.tin.org/bin/man.cgi?section=3&topic=shm_open
http://linux.die.net/man/3/shm_open

or some POSIX books say:

"For portable use, name should have an initial slash (/) and contain
no embedded slashes."

I wasn't expecting permission problems, though ;-) Could you tell me a
shared memory name that a user could use successfully in HP-UX?

Thanks for your quick reply, it's been really helpful.

Ion


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk