diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/sys/semctl.2 | 18 | ||||
-rw-r--r-- | lib/libc/sys/semop.2 | 133 |
2 files changed, 124 insertions, 27 deletions
diff --git a/lib/libc/sys/semctl.2 b/lib/libc/sys/semctl.2 index 4e3765c..6950371 100644 --- a/lib/libc/sys/semctl.2 +++ b/lib/libc/sys/semctl.2 @@ -107,6 +107,8 @@ Set the value of semaphore number .Fa semnum to .Fa arg.val . +Outstanding adjust on exit values for this semaphore in any process +are cleared. .It Dv GETPID Return the pid of the last process to perform an operation on semaphore number @@ -127,6 +129,8 @@ array pointed to by Set the values of all of the semaphores in the set to the values in the array pointed to by .Fa arg.array . +Outstanding adjust on exit values for all semaphores in this set, +in any process are cleared. .El .Pp The @@ -152,7 +156,10 @@ struct semid_ds { .Sh RETURN VALUES On success, when .Fa cmd -is one of GETVAL, GETNCNT, or GETZCNT, +is one of +.Dv GETVAL , GETNCNT +or +.Dv GETZCNT , .Fn semctl returns the corresponding value; otherwise, 0 is returned. On failure, -1 is returned, and @@ -174,7 +181,16 @@ the semaphore set's owner or creator. .It Bq Er EACCES Permission denied due to mismatch between operation and mode of semaphore set. +.It Bq Er ERANGE +.Dv SETVAL +or +.Dv SETALL +attempted to set a semaphore outside the allowable range +.Bq 0 .. Dv SEMVMX . .El .Sh SEE ALSO .Xr semget 2 , .Xr semop 2 +.Sh BUGS +.Dv SETALL +may update some semaphore elements before returning an error. 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. |