* Re: POSIX.4 Semaphore questions
1997-11-18 5:00 POSIX.4 Semaphore questions Scott Moore
@ 1997-11-19 5:00 ` Sajjad Lateef
1997-11-19 5:00 ` Dave Butenhof
1 sibling, 0 replies; 4+ messages in thread
From: Sajjad Lateef @ 1997-11-19 5:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1872 bytes --]
Hi,
Terrence Chan in "UNIX System Programming using C++" mentions
using RWX permissions for the user only in the an example. I could not
find a detailed explanation.
If the file paradigm for POSIX semaphores was taken a step beyond
the semaphore naming convention, it would not be too wrong to assume that
permissions would affect the semaphore (or IPC) as they do files.
I would imagine that your second call to sem_open would fail.
It might be easiest to write a small program and test it out.
(Which OS are you using? Solaris 2.6? Unfortunately I do not have access
to any system that support POSIX IPCs)
Question:
o Chan uses S_IRWXU to specify 0600 permissions. Is it suggested to use the
mnemonic instead of the numbers? (S_IRWU|S_IRG|S_IRO == 0644)
Thanks,
Sajjad
r H�����\x10����\x06��
Scott Moore (samoore@us.ibm.com) wrote:
: Hello-
: I am new to using POSIX.4 semaphores, and I can not find any
: documentation about how permissions are used. I know that on the
: sem_open(), if the caller has O_CREAT in the flags and a semaphore is
: created, permissions are set to the values specified by the mode
: parameter.
: What I don't get is what the permissions mean. Is it possible to have
: the permissions 0604 or 0602? In other words, does it make sense to
: have Read only (or write only) permissions to a POSIX semaphore? The
: reason I ask this is because System V semaphores this makes sense, but I
: am not sure of the POSIX implementation.
: If this is valid input on the sem_open, let's say that user A creates a
: named semaphore:
: sem_t semPtr = sem_open("/mysem", O_CREATE | O_EXCL, 0604, 0);
: And user B accesses the semaphore with:
: sem_t semPtr = sem_open("/mysem", 0);
: Would this fail for user B? Do you need both read and write access to
: get the semaphore?
: Thank you for any input!
: Scott
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: POSIX.4 Semaphore questions
1997-11-18 5:00 POSIX.4 Semaphore questions Scott Moore
1997-11-19 5:00 ` Sajjad Lateef
@ 1997-11-19 5:00 ` Dave Butenhof
1997-11-19 5:00 ` Scott Moore
1 sibling, 1 reply; 4+ messages in thread
From: Dave Butenhof @ 1997-11-19 5:00 UTC (permalink / raw)
Scott Moore wrote:
> Hello-
>
> I am new to using POSIX.4 semaphores, and I can not find any
> documentation about how permissions are used. I know that on the
> sem_open(), if the caller has O_CREAT in the flags and a semaphore is
> created, permissions are set to the values specified by the mode
> parameter.
>
> What I don't get is what the permissions mean. Is it possible to have
> the permissions 0604 or 0602? In other words, does it make sense to
> have Read only (or write only) permissions to a POSIX semaphore? The
> reason I ask this is because System V semaphores this makes sense, but I
> am not sure of the POSIX implementation.
>
> If this is valid input on the sem_open, let's say that user A creates a
> named semaphore:
>
> sem_t semPtr = sem_open("/mysem", O_CREATE | O_EXCL, 0604, 0);
>
> And user B accesses the semaphore with:
>
> sem_t semPtr = sem_open("/mysem", 0);
>
> Would this fail for user B? Do you need both read and write access to
> get the semaphore?
This is a fascinating issue, but, unfortunately, the standard isn't going
to help you much here. I suspect that any restriction of permissions with
semaphores is going to be fairly non-portable.
POSIX doesn't say what access is required to open a semaphore. It does
allow sem_open to return EACCES if "the permissions specified by oflag are
denied". (Which is a typo, in any case, since it is mode, not oflag, that
specifies permissions.) That implies that, if your second open were
sem_open("/mysem", O_CREAT, 0606, 0), it would fail with EACCES because the
original creator hadn't allowed write access to other users.
I can't imagine that you'd be able to open a semaphore without read
permission, and you certainly couldn't do anything with it. There are no
"pure write" operations on a semaphore -- only "read" and "modify"
operations (which would require a read followed by a write).
Even if an implementation allows you to open a semaphore without write
permission, I can't imagine that you'd be able to either post or wait on
the semaphore, since either requires modifying the semaphore data. On the
other hand, a read-only mapping would allow a resource monitor, for
example, to use sem_getvalue to show the current semaphore value, without
allowing it to modify the semaphore. Your mode, therefore, would allow
processes under the same uid full access to the semaphore, while any other
uid would be able to monitor the semaphore's value without affecting it.
Maybe that makes sense, sometimes. As I said, POSIX doesn't actually
guarantee that it's possible to open a read-only semaphore, though -- so
you're best off avoiding this.
/---------------------------[ Dave Butenhof ]--------------------------\
| Digital Equipment Corporation butenhof@zko.dec.com |
| 110 Spit Brook Rd ZKO2-3/Q18 http://members.aol.com/drbutenhof |
| Nashua NH 03062-2698 http://www.awl.com/cseng/titles/0-201-63392-2/ |
\-----------------[ Better Living Through Concurrency ]----------------/
^ permalink raw reply [flat|nested] 4+ messages in thread