summaryrefslogtreecommitdiffstats
path: root/lib/libc/sys/semop.2
diff options
context:
space:
mode:
authormr <mr@FreeBSD.org>2001-10-11 08:15:14 +0000
committermr <mr@FreeBSD.org>2001-10-11 08:15:14 +0000
commit188e03f8f915b4927b4647c7a022c4b273d50839 (patch)
tree6e7d3fd293eb6e4e9294689fba6d0217af2b9e62 /lib/libc/sys/semop.2
parent532fbd6c3cdd93c81c04a275eb0a7d898dcfc8a1 (diff)
downloadFreeBSD-src-188e03f8f915b4927b4647c7a022c4b273d50839.zip
FreeBSD-src-188e03f8f915b4927b4647c7a022c4b273d50839.tar.gz
Fix SysV Semaphore Handling.
Updated by peter following KSE and Giant pushdown. I've running with this patch for two week with no ill side effects. PR: kern/12014: Fix SysV Semaphore handling Submitted by: Peter Jeremy <peter.jeremy@alcatel.com.au>
Diffstat (limited to 'lib/libc/sys/semop.2')
-rw-r--r--lib/libc/sys/semop.2133
1 files changed, 107 insertions, 26 deletions
diff --git a/lib/libc/sys/semop.2 b/lib/libc/sys/semop.2
index ac4e79c..4e80f7c 100644
--- a/lib/libc/sys/semop.2
+++ b/lib/libc/sys/semop.2
@@ -70,7 +70,11 @@ and
.Fa sem_flg
determine an operation to be performed on semaphore number
.Fa sem_num
-in the set. The values SEM_UNDO and IPC_NOWAIT may be
+in the set. The values
+.Dv SEM_UNDO
+and
+.Dv IPC_NOWAIT
+may be
.Em OR Ns 'ed
into the
.Fa sem_flg
@@ -80,16 +84,19 @@ The operation performed depends as follows on the value of
.Fa sem_op :
.\"
.\" This section is based on the description of semop() in
-.\" Stevens, _Advanced Programming in the UNIX Environment_.
+.\" Stevens, _Advanced Programming in the UNIX Environment_,
+.\" and the semop(2) description in The Open Group Unix2 specification.
.\"
.Bl -bullet
.It
When
.Fa sem_op
-is positive, the semaphore's value is incremented by
+is positive and the process has alter permission,
+the semaphore's value is incremented by
.Fa sem_op Ns 's
-value. If SEM_UNDO is specified, the semaphore's adjust on exit
-value is decremented by
+value. If
+.Dv SEM_UNDO
+is specified, the semaphore's adjust on exit value is decremented by
.Fa sem_op Ns 's
value. A positive value for
.Fa sem_op
@@ -98,7 +105,8 @@ associated with the semaphore.
.It
The behavior when
.Fa sem_op
-is negative depends on the current value of the semaphore:
+is negative and the process has alter permission,
+depends on the current value of the semaphore:
.Bl -bullet
.It
If the current value of the semaphore is greater than or equal to
@@ -106,39 +114,54 @@ the absolute value of
.Fa sem_op ,
then the value is decremented by the absolute value of
.Fa sem_op .
-If SEM_UNDO is specified, the semaphore's adjust on exit
+If
+.Dv SEM_UNDO
+is specified, the semaphore's adjust on exit
value is incremented by the absolute value of
.Fa sem_op .
.It
-If the current value of the semaphore is less than
-.Fa sem_op Ns 's
-value, one of the following happens:
+If the current value of the semaphore is less than the absolute value of
+.Fa sem_op ,
+one of the following happens:
.\" XXX a *second* sublist?
.Bl -bullet
.It
-If IPC_NOWAIT was specified, then
+If
+.Dv IPC_NOWAIT
+was specified, then
.Fn semop
returns immediately with a return value of
.Er EAGAIN .
.It
-If some other process has removed the semaphore with the IPC_RMID
+Otherwise, the calling process is put to sleep until one of the following
+conditions is satisfied:
+.\" XXX We already have two sublists, why not a third?
+.Bl -bullet
+.It
+Some other process removes the semaphore with the
+.Dv IPC_RMID
option of
-.Fn semctl ,
-then
+.Fn semctl .
+In this case,
.Fn semop
returns immediately with a return value of
-.Er EINVAL .
+.Er EIDRM .
.It
-Otherwise, the calling process is put to sleep until the semaphore's
+The process receives a signal that is to be caught.
+In this case, the process will resume execution as defined by
+.Fn sigaction .
+.It
+The semaphore's
value is greater than or equal to the absolute value of
.Fa sem_op .
When this condition becomes true, the semaphore's value is decremented
by the absolute value of
.Fa sem_op ,
-and the semaphore's adjust on exit value is incremented by the
+the semaphore's adjust on exit value is incremented by the
absolute value of
.Fa sem_op .
.El
+.El
.Pp
A negative value for
.Fa sem_op
@@ -149,11 +172,42 @@ available.
.It
When
.Fa sem_op
-is zero, the process waits for the semaphore's value to become zero.
-If it is already zero, the call to
+is zero and the process has read permission,
+one of the following will occur:
+.Bl -bullet
+.It
+If the current value of the semaphore is equal to zero
+then
.Fn semop
-can return immediately. Otherwise, the calling process is put to
-sleep until the semaphore's value becomes zero.
+can return immediately.
+.It
+If
+.Dv IPC_NOWAIT
+was specified, then
+.Fn semop
+returns immediately with a return value of
+.Er EAGAIN .
+.It
+Otherwise, the calling process is put to sleep until one of the following
+conditions is satisfied:
+.\" XXX Another nested sublists
+.Bl -bullet
+.It
+Some other process removes the semaphore with the
+.Dv IPC_RMID
+option of
+.Fn semctl .
+In this case,
+.Fn semop
+returns immediately with a return value of
+.Er EIDRM .
+.It
+The process receives a signal that is to be caught.
+In this case, the process will resume execution as defined by
+.Fn sigaction
+.It
+The semaphore's value becomes zero.
+.El
.El
.Pp
For each semaphore a process has in use, the kernel maintains an
@@ -170,16 +224,20 @@ will fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
No semaphore set corresponds to
-.Fa semid .
+.Fa semid ,
+or the process would exceed the system-defined limit for the number of
+per-process SEM_UNDO structures.
.It Bq Er EACCES
Permission denied due to mismatch between operation and mode of
semaphore set.
.It Bq Er EAGAIN
-The semaphore's value was less than
-.Fa sem_op ,
-and IPC_NOWAIT was specified.
+The semaphore's value would have resulted in the process being put to sleep
+and
+.Dv IPC_NOWAIT
+was specified.
.It Bq Er E2BIG
Too many operations were specified.
+.Bq Dv SEMOPM
.It Bq Er EFBIG
.\"
.\" I'd have thought this would be EINVAL, but the source says
@@ -187,7 +245,30 @@ Too many operations were specified.
.\"
.Fa sem_num
was not in the range of valid semaphores for the set.
+.It Bq Er EIDRM
+The semaphore set was removed from the system.
+.It Bq Er EINTR
+The
+.Fn semop
+call was interrupted by a signal.
+.It Bq Er ENOSPC
+The system SEM_UNDO pool
+.Bq Dv SEMMNU
+is full.
+.It Bq Er ERANGE
+The requested operation would cause either
+the semaphore's current value
+.Bq Dv SEMVMX
+or its adjust on exit value
+.Bq Dv SEMAEM
+to exceed the system-imposed limits.
.El
.Sh SEE ALSO
.Xr semctl 2 ,
-.Xr semget 2
+.Xr semget 2 ,
+.Xr sigaction 2
+.Sh BUGS
+.Fn Semop
+may block waiting for memory even if
+.Dv IPC_NOWAIT
+is specified.
OpenPOWER on IntegriCloud