Nate Eldredge <n
...@vulcan.lan> wrote:
> Semaphores are not files, and the name of a semaphore is not a pathname.
> RTM.
> From sem_open(3):
> sem_open() creates a new POSIX semaphore or opens an existing
> semaphore. The semaphore is identified by name. For details of
> the construction of name, see sem_overview(7).
> From sem_overview(7):
> Named semaphores
> A named semaphore is identified by a name of the form
> /somename. Two processes can operate on the same named
> semaphore by passing the same name to sem_open(3).
> Changing SEM_NAME1 to "/nimeni" makes it succeed. Note that this
> doesn't imply that anything gets created in the root directory.
> Checking the value of errno would have shown that it gets set to ENOENT,
> which should suggest that something is wrong with the name. man perror.
I think it's not just a question of R(F)TM here since a bit of a
re-write of the man pages could IMHO make this a lot clearer. No-
thing in the wording with '/somename' indicates that there are no
slashes allowed in 'somename'. And getting ENOENT is a bit of a
red hering - I normally would expect that when I try to open a file
that does not exist (or when I use a path that does not exist).
Translating that in this case to mean "you used a name that is not
well-formed" takes quite a bit of imagination. All that makes it
look as if the name has something to do with files (or at least
file names) and thus it can be rather confusing.
Moreover, the man page for sem_open (from May 2008) tells about
ENOENT:
The O_CREAT flag was not specified in oflag, and no semaphore
with this name exists.
but, clearly, O_CREAT was specified in the OPs case. And the
wording in SUSv3
ENOENT O_CREAT is not set and the named semaphore does not exist.
doesn't seem to say anything different.
And it gets worse by the fact that the slash at the start of the
name is actually not required - if I call sem_open() with "somename"
instead of "/somename" (and haven't done that before) it works...
From playing around with the different possibilities it looks as
if a starting slash may simply be dropped, while any slash in
'name' (except at the start) results in failure with ENOENT.
Now SUSv3 says:
It is unspecified whether the name appears in the file system
That makes it look to me as if calling sem_open() creates a file
with 'name' is actually an option...
and is visible to functions that take pathnames as arguments. The
name argument conforms to the construction rules for a pathname.
So, shouldn't then a 'name' with embedded slashes be just fine?
If name begins with the slash character, then processes calling
sem_open() with the same value of name shall refer to the same
semaphore object, as long as that name has not been removed.
WTF is meant with "that name has not been removed"? Do they mean
"the semaphore associated with that name has not been removed"?
If name does not begin with the slash character, the effect is
implementation-defined. The interpretation of slash characters other
than the leading slash character in name is implementation-defined.
I guess it would be nice if the man page would be a bit clearer
about what actually is required and what's actually defined by the
implementation on Linux. I guess I have to come up with a patch for
those man pages;-)
Regards, Jens
--
\ Jens Thoms Toerring ___ j...@toerring.de
\__________________________ http://toerring.de